AndroidのAlertDialogは、ラジオボタンやメッセージが表示されません
-
26-09-2019 - |
質問
私のアプリで私はListActivityで長いクリックでコンテキストメニューを表示。オプションの一つは、「優先度」3ラジオボタンを選択してAlertDialogをポップアップします。問題は、それは私が設定されていることを私の3つの選択肢のない空のダイアログボックス、またはメッセージを表示し、です。ここに私のコードです..
protected Dialog onCreateDialog(int id) {
AlertDialog dialog;
switch(id) {
case DIALOG_SAB_PRIORITY_ID:
final CharSequence[] items = {"High", "Normal", "Low"};
AlertDialog.Builder builder = new AlertDialog.Builder(SabMgmt.this);
builder.setMessage("Select new priority")
.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
}
});
dialog = builder.create();
break;
default:
dialog = null;
}
return dialog;
}
私が代わりに正と負のボタンで.setSingleChoiceItemsを交換する場合、期待どおりは、それがボタンとメッセージを表示します。私は、ラジオボタンの私のリストを設定する際に間違って何をしているのですか?ここに私の呼び出し元のコードが同様である..
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case R.id.sabdelete:
// Correct position (-1) for 1 header
final SabQueueItem qItem = (SabQueueItem) itla.getItem(info.position-1);
SabNZBdUtils.deleteItem(qItem.getNzo_id());
getQueue();
ListView lv = getListView();
View v = lv.findViewById(R.id.sablistheader);
setHeader(v);
itla.notifyDataSetChanged();
return true;
case R.id.sabpriority:
showDialog(DIALOG_SAB_PRIORITY_ID);
return true;
default:
return super.onContextItemSelected(item);
}
}
解決
それを考え出しました!私の代わりにbuilder.setTitleのsingleChoiceItemダイアログ上builder.setMessageを使用していました。また、ラジオボタンの選択肢を使用して、ダイアログは、メッセージ、タイトルだけを設定サポートしていないようです。メソッドはを通して提供されていることを奇妙に思えます。とにかく、ここでの作業コードがある..
protected Dialog onCreateDialog(int id) {
AlertDialog dialog;
switch(id) {
case DIALOG_SAB_PRIORITY_ID:
final CharSequence[] items = {"High", "Normal", "Low"};
AlertDialog.Builder builder = new AlertDialog.Builder(SabMgmt.this);
builder.setTitle("Select new priority")
.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
}
});
dialog = builder.create();
break;
default:
dialog = null;
}
return dialog;
所属していません StackOverflow