showDialog en activité ne pas afficher de dialogue
-
14-10-2019 - |
Question
Voici mon code:
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;
}
}
Le showDialog
n'affiche pas la boîte de dialogue. J'ai utilisé le Débogueur et il n'exécute ces déclarations, mais la boîte de dialogue ne montre pas.
La solution
Vous n'êtes pas breakaing de vos déclarations de commutation à onCreateDialog. Est-ce que vous définissez simplement null chaque fois?
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow