开发者

Android. Launch dialog from context menu

开发者 https://www.devze.com 2023-04-07 17:38 出处:网络
I have a listView and want on long press show my custom dialog. How I cat to do this? All my attempts brought nothing to me. Dialog never shows, ANR is occurs.

I have a listView and want on long press show my custom dialog. How I cat to do this? All my attempts brought nothing to me. Dialog never shows, ANR is occurs.

 @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;
            S开发者_如何学Pythonystem.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);

}

Rating dialog never shows, toast works perfectly. It is necessary to show context menu befor dialog or I can launch my dialog from onCreateContextMenu()?

Thanks!


You may need to show the context menu before the dialog. You could then have an option to rate.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号