I want to make a view where I can select multiple items from listview and also side by side am changing the color of selected list item and saving that item into my arraylis
The solution (idea) from Jason Robinson is good, but there is an error! You can not remove item from ArrayList by it's value!!!
Method ArrayList.remove(int) takes item's index as parametr!
If you want to use an ArrayList<
, you need to find index ot item you want to remove. For example:Integer
>
private int getIndex(int value) {
int index = -1;
for(int i=0; i
Or use method ArrayList.indexOf(Object)
to obtain index.
And now, how to get reference to your adapter from FragmenList or ListActivity. Simply use class variable:
public class SimpleFragment extends ListFragment {
private MyCustomAdapter mAdapter;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mAdapter = new MyCustomAdapter(getActivity(), R.layout.row_layout);
setListAdapter(mAdapter);
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
// now you have an access to your adapter through class variable mAdapter
}
}