带有Array Adapter的警报对话框没有捕获点击次数

时间:2016-08-02 10:45:05

标签: android android-alertdialog

我正在创建(或尝试)当用户点击播放视频时弹出的警告对话框,如果有保存的简历点,他们可以选择恢复,重新开始或取消操作。由于我想在对话框中包含恢复时间(例如“从08:32恢复播放”)

对话框显示正确的项目,格式正确,但点击时没有任何反应。我想知道我哪里出错了。

Java代码:

final ArrayAdapter<String> itemVals = new ArrayAdapter<>(Docket.CURRENT_CONTEXT,
        R.layout.adapter_simple_list_item, R.id.list_item);

String optionStartBeginning = getString(R.string.media_play_no_resume);
itemVals.add(optionStartBeginning);

if (CastingBridge.getHasResume()) {
    String optionResume = "Resume playback from "+ StringFormatter.intMsTimeToString(CastingBridge.RESUME_TIME);
    itemVals.add(optionResume);
}

itemVals.add(getString(R.string.cancel));

AlertDialog.Builder builder = new AlertDialog.Builder(Docket.CURRENT_CONTEXT);
builder.setTitle(R.string.resume_offer_title)
        .setAdapter(itemVals, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Log.i(TAG, "onClick: Chosen idx is "+ which);
            }
        }).setCancelable(true);

AlertDialog alert = builder.create();
alert.show();

布局文件R.layout.adapter_simple_list_item

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical">

    <com.rey.material.widget.TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:focusable="false"
        style="@style/Material.Drawable.Ripple.Touch.MatchView"
        app:rd_enable="true"
        android:id="@+id/list_item"
        android:text="@string/test_string"
        android:paddingTop="20dp"
        android:paddingBottom="20dp"
        android:paddingLeft="24dp"
        android:paddingRight="24dp"
        android:textSize="18sp" />

</LinearLayout>

点击时唯一发生的事情就是打印在logcat中:

D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN

我不知道的任何明显错误? 提前感谢您的任何答案。

2 个答案:

答案 0 :(得分:1)

Editted:

此代码正常运行

Java代码:

final ArrayAdapter<String> itemVals = new ArrayAdapter<String>(_A,
                    R.layout.check, R.id.list_item);

            String optionStartBeginning = "No resaume";
            itemVals.add(optionStartBeginning);

        /*    if (CastingBridge.getHasResume()) {
                String optionResume = "Resume playback from Here";
                itemVals.add(optionResume);
            }*/

            itemVals.add("Cancel");

            AlertDialog.Builder builder = new AlertDialog.Builder(_A);
            builder.setTitle("Simple")
                    .setAdapter(itemVals, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Log.i("", "onClick: Chosen idx is "+ which);
                        }
                    }).setCancelable(true);

            AlertDialog alert = builder.create();
            alert.show();

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/list_item"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:focusable="false"
        android:paddingBottom="20dp"
        android:paddingLeft="24dp"
        android:paddingRight="24dp"
        android:paddingTop="20dp"
        android:text="Text"
        android:textSize="18sp" />

</LinearLayout>

我已经用上面的代码检查了它的工作

答案 1 :(得分:0)

我会尝试删除可聚焦属性

mysql

或最终将其设置为&#34; true&#34;