android - AlertDialog 未加载

标签 android listview android-alertdialog

我有一个 ListView 并且我在其中放置了一个 onClickListener。当我单击它时,它应该运行一个 AlertDialog 但它似乎不起作用。 AlertDialog 应该显示 ListView 中的一些字符串。这是我正在使用的代码。

 listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                PopUpAlert(id);

            }
        });


 private void PopUpAlert(final long id) {

            Cursor cursor = dbHelper.getAllReviewRows(id);

            if (cursor.moveToFirst()) {

                //Preparing variables to use in message from Establishment record in Database

                final String SName = cursor.getString(dbHelper.COL_REV_STATION_NAME);
                String Date = cursor.getString(SQL.COL_DATE);
                String SFacility = cursor.getString(SQL.COL_REV_FACILITY);
                String Rating = cursor.getString(SQL.COL_RATING);
                String Comment = cursor.getString(SQL.COL_COMMENTS);

                // building a drill down information message and displaying it in an Alert Dialog
                new AlertDialog.Builder(this)
                        .setTitle("Facilities Review App")
                        .setMessage("You Selected:\n"
                                + "Station Name: " + SName + "\n" + "Date: " + Date
                                + "\n" + "Facility: " + SFacility + "\n" + "Rating: " + Rating
                                + "\n" + "Comment: " + Comment)
                        .setPositiveButton("Add Image", new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                // calling method to add a review for that particular establishment
                                addImage(SName);

                            }
                        })
                        .setNegativeButton("Delete", new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                // calling method to delete that particular establishment


                            }


                        });

            }

        }

最佳答案

您没有在 AlertDialog 上调用 show():

new AlertDialog.Builder(this)
 .setTitle("Facilities Review App")
 .setMessage("...")
 .setPositiveButton(..)
 .setNegativeButton(..)
 .show();

在这里您可以找到 AlertDialog.Builder.show() 的文档

关于android - AlertDialog 未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29864015/

相关文章:

android - 警报对话框上带有多选复选框的列表?

android - 无法关闭 android 中的警报对话框

java - findFragmentByTag 不起作用

java - Foursquare API java 只给出一个附近的位置

java - Android 中 float 增量的问题

java - 如何在 ListView 中保存多个动态生成的复选框的状态? (安卓Java)

android - 如何为 alertDialog 创建自己的主题?

android - 我可以使用 android camera intent 拍摄黑白照片吗?

javascript - 颜色框和 ListView

listview - 在 Xamarin.Forms Windows Phone 中查看单元格错误