我有一个listView,想要长按显示我的自定义对话框。我怎么这么做?我所有的尝试都没有带给我任何东西对话框从不显示,ANR发生。
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
int type = ExpandableListView.getPackedPositionType(info.packedPosition);
int group = ExpandableListView.getPackedPositionGroup(info.packedPosition);
int child = ExpandableListView.getPackedPositionChild(info.packedPosition);
if (type == 1) {
menu.add("rating");
}
}
@Override
public boolean onContextItemSelected(MenuItem menuItem) {
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
int rating = msg.arg1;
System.out.println("Rating = " + rating);
}
};
System.out.println("Create rating dialog");
Toast.makeText(MyListActivity.this, "Ass", Toast.LENGTH_SHORT).show();
// new RatingDialog(MyListActivity.this, handler).show();
return super.onContextItemSelected(menuItem);
}
评级对话框从不显示,吐司效果很好。有必要显示上下文菜单,或者我可以从onCreateContextMenu()启动我的对话框吗?
谢谢!
答案 0 :(得分:0)
您可能需要在对话框之前显示上下文菜单。然后,您可以选择评分。