Just stated learning about the ICS Actionbar. I am working with Action Bar Sherlock to be backwards compatible for things I want to do and have gone though lots of the source code on its samples.
I have 3 image views, I want to set a listener for a long click on all 3. When a user long clicks one I will show an ActionMode over the action bar letting them take a picture. Since the action bar seems to work just like the menu, how do I know what ImageView triggered my ActionMode after they click a button from it?
Don't have a lot of code done right now because I am just starting looking into it and this was the first thing I wanted to do.
To initiate an action mode, you need to provide an instance of the ActionMode.Callback
class. For something like this, you should create a constructor inside this class which accepts some relevant information about the image view.
public static class ImageActionMode extends ActionMode.Callback {
private final int viewId;
public ImageActionMode(View view) {
viewId = view.getId();
}
public boolean onActionItemClicked (ActionMode mode, MenuItem item) {
//Do something with viewId as the target
}
//Other callbacks
}
You could also keep a reference to the full ImageView
or anything else that is what you need to respond to the options item.
Now when you start the action mode you would do something like this:
public void onLongPress(View view, /*whatever else...*/) {
startActionMode(new ImageActionMode(view));
}