Java 活动中的showDialog未显示对话框
这是我的密码:Java 活动中的showDialog未显示对话框,java,android,dialog,showdialog,Java,Android,Dialog,Showdialog,这是我的密码: public class TasksList extends ListActivity { ... private static final int COLUMNS_DIALOG = 7; private static final int ORDER_DIALOG = 8; private Bundle bundle = new Bundle(); ... /** * @see android.app.Activity#
public class TasksList extends ListActivity {
...
private static final int COLUMNS_DIALOG = 7;
private static final int ORDER_DIALOG = 8;
private Bundle bundle = new Bundle();
...
/**
* @see android.app.Activity#onCreateDialog(int)
*/
@Override
protected Dialog onCreateDialog(int id) {
Dialog dialog;
final String[] columns;
Cursor c = managedQuery(Tasks.CONTENT_URI, null, null, null, null);
columns = c.getColumnNames();
final String[] order = { "Ascending", "Descending" };
switch (id) {
case COLUMNS_DIALOG:
AlertDialog.Builder columnDialog = new AlertDialog.Builder(this);
columnDialog.setSingleChoiceItems(columns, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
bundle.putString("column", columns[which]);
}
});
dialog = columnDialog.create();
break;
case ORDER_DIALOG:
AlertDialog.Builder orderDialog = new AlertDialog.Builder(this);
orderDialog.setSingleChoiceItems(order, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String orderS;
if (order[which].equalsIgnoreCase("Ascending"))
orderS = "ASC";
else
orderS = "DESC";
bundle.putString("order", orderS);
}
});
dialog = orderDialog.create();
break;
default:
dialog = null;
break;
}
return dialog;
}
/**
* @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case SORT_MENU:
showDialog(COLUMNS_DIALOG);
showDialog(ORDER_DIALOG);
String orderBy = bundle.getString("column") + bundle.getString("order");
Cursor tasks = managedQuery(Tasks.CONTENT_URI, projection, null, null, orderBy);
adapter = new TasksAdapter(this, tasks);
getListView().setAdapter(adapter);
break;
case FILTER_MENU:
break;
}
return false;
}
}
showDialog
不显示该对话框。我使用了调试器,它确实执行了这些语句,但是对话框没有显示。您没有在onCreateDialog中中断switch语句。你每次都只是将其设置为空吗?我刚刚修复了这个问题,但我仍然在“String orderBy=bundle.getString(“column”)+bundle.getString(“order”);”处得到一个“NullPointerException”。好吧,如果你“仍然”得到一个NPE,你应该首先提到你得到了一个NPE。您在哪里定义捆绑
?我只是看到它正在被使用。对不起,我忘了把它包括在内。异常仍然发生,我确实发生了。这是以“private Bundle”开头的一行。不,这是因为在android绘制对话框之前,您试图使用用户与对话框交互的结果。正如我所说,显示对话框是异步的。不能像正在使用的那样使用这些值。时期