带有阵列适配器的警报对话框未捕获点击
Alert Dialog with Array Adapter is not capturing clicks
我正在创建(或尝试)一个警告对话框,当用户点击播放视频时弹出,如果有保存的恢复点,他们可以选择恢复、重新开始或取消那个行动。因为我想在对话框中包含恢复时间(例如 "Resume Playback from 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
有什么我不知道的明显错误吗?
预先感谢任何答案。
我会尝试删除 focusable 属性
android:focusable="false"
或最终设置为"true"
已编辑:
此代码有效
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>
我已经用上面的代码检查过它可以正常工作
我正在创建(或尝试)一个警告对话框,当用户点击播放视频时弹出,如果有保存的恢复点,他们可以选择恢复、重新开始或取消那个行动。因为我想在对话框中包含恢复时间(例如 "Resume Playback from 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
有什么我不知道的明显错误吗? 预先感谢任何答案。
我会尝试删除 focusable 属性
android:focusable="false"
或最终设置为"true"
已编辑:
此代码有效
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>
我已经用上面的代码检查过它可以正常工作