This question already has answers here:
RecyclerView stackFromBottom
(2 answers)
Closed 6 years ago.
How can I set stackFromBottom(boolean) from ListView in RecyclerView? I need the first element in the list to be last element in the view.
For example, I have a list with 10 elements. On top of the view, I have an element with index 9, and at the bottom of the view I have an element with index 0. After I call notifyDataSetChanged() new elements are added to the bottom of the view.
In ListView, I use the setStackFromBottom method. Does RecyclerView have alternatives for this?
setReverseLayout(Boolean) method from RecyclerView.LinearLayoutManager - it's my choice.
setStackFromEnd(boolean) method was added for support with ListView
I have never used it, but I think this could be a method you are looking for: setStackFromEnd(boolean) from RecyclerView.LinearLayoutManager.
Related
This question already has answers here:
Lint error "Do not treat position as fixed; only use immediately..."
(2 answers)
Closed 6 years ago.
Here is my code -
public void onBindViewHolder(myViewHolder holder, int position) {
//1. details obj = list.get(holder.getAdapterPosition());
//2. details obj = list.get(position);
holder.position = position;
}
I am getting a warning
Do not treat position as fixed; only use immediately and call
holder.getAdapterPosition() to look it up later RecyclerView will not
call onBindViewHolder again when the position of the item changes in
the data set unless the item itself is invalidated or the new position
cannot be determined. For this reason, you should only use the
position parameter while acquiring the related data item inside this
method, and should not keep a copy of it. If you need the position of
an item later on (e.g. in a click listener), use getAdapterPosition()
which will have the updated adapter position later.
So i am confused from 1 and 2 which should i prefer and why? As it says getAdapterPosition() gives updated position and i am getting values from list based on position.
Thank you.
The warning you get is not about using position or getAdapterPosition(). It is about saving the position:
holder.position = position;
You don't need to save the position in your holder, because its position can change and you can always get its position by calling holder.getAdapterPosition();
From the docs:
Note that unlike ListView, RecyclerView will not call this method
again if the position of the item changes in the data set unless the
item itself is invalidated or the new position cannot be determined.
For this reason, you should only use the position parameter while
acquiring the related data item inside this method and should not keep
a copy of it. If you need the position of an item later on (e.g. in a
click listener), use getAdapterPosition() which will have the updated
adapter position.
About which to use:
Both should return the same result if called inside the onBindViewHolder method. I would recommend using position because it is easiest and safest.
This question already has answers here:
How to add icons to items in a navigation drawer
(2 answers)
Closed 8 years ago.
Does anyone know how to add icons like this in the navigation drawer?
http://i.stack.imgur.com/JvzOb.png
(cant add images until I have 10 rep. points)
The content of the DraweLayoutis a ListView. So, you must set a custom adapter to the ListView, providing on the getView method the view desired. A good tutorial.
This question already has answers here:
Populating a ListView using an ArrayList?
(6 answers)
Closed 9 years ago.
I'm programming an Android application and one feauture is a ListView generated and populated by a MySQL Database.
This is the outputted ArrayList:
DatabaseHandler db = new DatabaseHandler(this);
List<Suspect> list = db.getAllContacts();
Do I use a cursor to input it in my ListView?
Any code would be appreciated..
I recommend you to use CursorAdapter in case you don't need any data manipulations after the query.
If you want to use List so try ArrayAdapter.
If you need to modify the data after it is captured from the database and have the view updated I'd suggest you create an arrayList of , and then you can use a custom Array Adapter like shown here. If you then change the underlying data, you can use adapter.notifyDataSetChanged()
This question already has an answer here:
How to create a reorder-able TableView in JavaFx
(1 answer)
Closed 7 years ago.
I'm having trouble with JavaFXs ListView items. The thing is that I can not find a way to reorder them at runtime. Just with dragging item with mouse. Also I want to change items order in underlaying ObservableList.
How could this be done?
You can change the order of the ObservableList that forms the underlying model of the ListView at any time to change the order of your list view items...
... for example: to use a Comparator to re-order the contents of your list view you could use something like:
javafx.scene.control.ListView<TYPE> listView; // Your ListView, defined somewhere else.
java.util.Collections.sort(listView.getItems(), new java.util.Comparator<TYPE>() {
#Override
public int compare(TYPE o1, TYPE o2) {
// Implement your comparator here.
}
});
... whereas "TYPE" matches the type of your ListView instance.
See http://docs.oracle.com/javafx/2/api/javafx/scene/control/ListView.html#itemsProperty for further details of the list view items definition.
You can add, remove and shuffle the items around as you like and the ListView will automatically adjust it's appearance...
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Horizontal ListView in Android?
I am working on android and I want to make ListView to scroll Horizontal.
Is there any idea to do it using android property for ListView?
Please help me.
There is an excelent article about this on dev-smart
Horizontal Scroll in ListView
I hope this helps
Possible duplicate of :
Horizontal ListView in Android?
And there is one more example :
http://nan-devblog.blogspot.in/2008/12/android-how-to-use-horizontal-scrolling.html