为什么我的dialog.show()不起作用?

vc6uscn9  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(303)

我想使用警报对话框更新数据,但当我尝试使用show()显示警报对话框时,它不会弹出。有人能帮帮我吗。
代码如下:

mListView.setOnItemLongClickListener (new AdapterView.OnItemLongClickListener () {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            final CharSequence[] items = {"Update", "Delete"};
            AlertDialog.Builder dialog = new AlertDialog.Builder (FoodList.this);

            dialog.setTitle ("Choose an action");
            dialog.setItems (items, new DialogInterface.OnClickListener () {
                @Override
                public void onClick(DialogInterface dialogInterface, int which) {
                    if(which == 0){
                        Cursor c = AddFood.dbHelper.getData ("SELECT id FROM food");
                        ArrayList<Integer> arrID = new ArrayList<Integer> ();
                        while (c.moveToNext ()){
                            arrID.add(c.getInt (0));
                        }
                        showDialogUpdate (FoodList.this,arrID.get(position));

                    }
                    if(which ==1){

                        Cursor c = AddFood.dbHelper.getData ("SELECT * FROM food");
                        ArrayList<Integer> arrID = new ArrayList<Integer> ();
                        while (c.moveToNext ()){
                            arrID.add (c.getInt (0));
                        }
                        showDialogDelete(arrID.get(position));
                    }
                }

            });
            dialog.show ();
            return true;
        }

    });

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题