我有一个带有EditText
盒子和ListView
. 我也Override
onCreateContextMenu
喜欢这个:
@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();
这是问题。 当我长按剪切/复制/粘贴/等框onCreateContext
时,系统可以调用它。EditText
长按我的也可以调用ListView
。当系统从EditText
.
这是解决方案:我需要在onCreateConextMenu
创建时比较视图。但是,我不知道该怎么做,也无法在任何地方找到解决方案。我有 Logg'ed View v,以及我活动中的所有其他视图,它总是指向我的ListView
...
我怎样才能创建这样的代码:
if (view passed in is from ListView) {
MenuItem Edit = menu.findItem(R.id.editComment);
MenuItem Delete = menu.findItem(R.id.deleteComment);
// do other things
}
谁能指导我?我一直在寻找一个星期...