I am creating an android application including vehicle information to list view. when clicking the list item it displayed information about the vehicle. Now I want to add Delete and Edit vehicle information without entering the list item. is it possible to add double click and long click for list item for these two events(delete and edit actions) without entering the list item?
Asked
Active
Viewed 64 times
-1
-
Yes, You can add `onItemLongClickListner` to your `ListView` ( link : http://developer.android.com/reference/android/widget/AdapterView.OnItemLongClickListener.html ) – Ye Lin Aung Apr 25 '14 at 10:50
-
is it possible to double click or something another action to list item to give edit action? – user2881604 Apr 25 '14 at 11:16
2 Answers
0
You will need index number of element in array to delete it from datasource.
ArrayList<Integer> list = new ArrayList<Integer>();
if(list.contains(3)){//check if the list contains the element
list.get(list.indexOf(3));//get the element by passing the index of the element
}
About Your second question: Yes it is possible to delete item on LongPress
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public void onItemLongClick((AdapterView<?> parent, View view, int position, long id) {
MyAdapter adapter = (MyAdapter)listView.getAdapter();
myAdapter.removeItemAt(pos); // you need to implement this method
myAdapter.notifyDataSetChanged();
}
));

iAhmed
- 6,556
- 2
- 25
- 31