I have made a ContextMenu
for a ListView
, and everything is working perfectly. However, I can't figure out how I can send selected items to another activity?
I have looked at a lot of tutorials but found no solution.
Each item represents two columns with two strings (product, price) parsed with a JSON string.
listViewProduse.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
listViewProduse.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
@Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
final int checkedCount = listViewProduse.getCheckedItemCount();
mode.setTitle(checkedCount + " product selected");
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.main_context, menu);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch (item.getItemId()){
case R.id.add_id:
SparseBooleanArray selected = adapter.getSelectedIds();
String copyText="";
for (int i = (selected.size() - 1); i >= 0; i--){
if (selected.valueAt(i)){
VanzatorProduse selectedListItem = adapter.getItem(selected.keyAt(i));
}
}
mode.finish();
return true;
default:
return false;
}
}