I have an activity with an EditText box and a ListView. I also Override onCreateContextMenu like this:
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
android.view.MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.comments_context, menu);
menu.setHeaderTitle("Available Actions");
Log.d("v: ", String.valueOf(v));
MenuItem Edit = menu.findItem(R.id.editComment);
MenuItem Delete = menu.findItem(R.id.deleteComment);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
int position = info.position;
ListView lv = (ListView) v;
int firstVisible = lv.getFirstVisiblePosition();
View rowView = lv.getChildAt(position - firstVisible);
ReviewUser = ((TextView) rowView.findViewById(R.id.labelReviewCommentUser)).getText()
.toString();
ReviewComment = ((TextView) rowView .findViewById(R.id.labelReviewComment)).getText().toString();
Here is problem. onCreateContext can be called by system when I longpress an EditText box for cut/copy/paste/etc. It also can be called when you long click my ListView. I get a null crash at the Two TextViews at the bottom’s above in last line when system calls onCreateContextMenu from EditText.
Here is solution: I need to compare views when onCreateConextMenu is created. However, i do not know how to do this and can’t find solution anywhere. I have Logg’ed View v, and all other views in my activity and it ALWAYS points to my ListView…
How can I create code that says:
if (view passed in is from ListView) {
MenuItem Edit = menu.findItem(R.id.editComment);
MenuItem Delete = menu.findItem(R.id.deleteComment);
// do other things
}
Can anyone guide me? I’ve been looking for a week on this…
Not the final solution, because what was happening may actually be a bug, but simply moving the
EditTextout of theListViewheader but to the main XML file allowed me to bypass the issue.