by dmurarik » Tue Oct 26, 2010 6:16 pm
ItemsList= new ArrayList<String>();
TheListView = (ListView)findViewById(R.id.ListView01);
TheListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, ItemsList));
TheListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);//this is important
//instead of a save button use your menu option
Button save = (Button)findViewById(R.id.ButtonchannelsSave);
save.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
if(TheListView != null)
a = new SparseBooleanArray();
a.clear();
a = TheListView.getCheckedItemPositions();
long[] b;
b = TheListView.getCheckItemIds();
if(a.size() > 0 && a != null)
{
for (int i = 0; i < a.size(); i++)
{
if(a.valueAt(i) == true)
{
ItemsList.get(a.keyAt(i)).toString(); // this will give you the value of the item checked. say"Item1". At this point you could remove them from the current list of items.
}
}
}
}
});
}
In the above example I save the list of items. You could update ItemsList and then call
TheListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, ItemsList)); or TheListView.invalidate(); should do it.
again.