Answer the question
In order to leave comments, you need to log in
Editable items in ListView?
Hello,
there is a ListView full of text (one line per item), I want that when you click on the item, the field can be edited and there are two small icons on the side, confirm or cancel.
It seems to me that this should be the standard API. just don't know how to do it.
And another question, for example, how can I make it so that you can select several items or there is a button - select all. There should also be a standard API.
Or tell me where to look how to do this.
Thank you!
Answer the question
In order to leave comments, you need to log in
If something is not obvious how to do it, or this cannot be achieved by the standard layout of elements (or the speed is not satisfactory, etc.), then it is better to write a custom element with the necessary functionality.
Regarding the selection of list elements, there is such an article (in Russian) startandroid.ru/ru/uroki/vse-uroki-spiskom/83-urok-43-odinochnyj-i-mnozhestvennyj-vybor-v-list.html . Maybe it will help you.
And about changing the data directly in the list - if you are going to reuse the view that comes to the getView method, you need to remember the position of the element being edited in the adapter and check in getView whether it is or not. And just issue the corresponding view.
about editing elements - something like this:
public void onItemClick(AdapterView list, View v, int position, long id) {
TextView text_view = (TextView) v.findViewById(R.id.item_text_view);
String text = text_view.getText();
v.removeView(text_view);
LayoutInflater li = getLayoutInflater(this);
View editable_view = li.inflate(R.layout.editable_item, null);
editable_view.findViewById(R.id.editable_edit_text).setText(text);
v.addView(editable_view);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question