I have a Dialog that has a ListView in it, and when you select an item a contextual actionBar needs to appear.
This is what I have so far This is inside my Dialog's ListView adapter's getView method. searchView is the view. bAct is my Activity that starts the dialog.
final LinearLayout searchView;
final LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
searchView = new LinearLayout(getContext());
vi.inflate(resource, searchView, true);
}
else
{
searchView = (LinearLayout) convertView;
}
//Some code setting up some textview etc...
searchView.startActionMode(bAct.savedSearchMode);
And in my Activity I have
public ActionMode.Callback savedSearchMode = new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
MenuInflater inflater = new MenuInflater(ActivityViewTimetable.this);
inflater.inflate(R.menu.saved_searches, menu);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
return false;
}
@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.run:
progress.setTitle("Searching...");
progress.setMessage("Fetching classes from the server");
progress.show();
AsyncForTimetable(typeID, classID, venueIds.values(), true);
hideSavedSearchDialog();
break;
case R.id.delete:
ToastMe("Delete search");
break;
default:
ToastMe("Unknown: "+menuItem.getTitle());
break;
}
actionMode.finish();
return false;
}
@Override
public void onDestroyActionMode(ActionMode actionMode) {
actionMode.finish();
}
};
The whole thing works once. I can open the Dialog, get the ActionBar to change to my context items, and run a search, but once I try to do it again the actionbar doesn't change.
Can anyone see what I've got wrong?
If you need any other bits of code posting let me know