private void selectFromFactory(
      final IFilterFactory factory,
      final String menuTitle,
      final RunnableWithArgument<IFilter> runAfterwards) {
    final IFilter[] filters = factory.getFilters();
    if (filters.length == 1) {
      runAfterwards.run(filters[0]);
      return;
    }

    final AlertDialog.Builder builder = new AlertDialog.Builder((Activity) activity);
    builder.setTitle(menuTitle);

    final ArrayAdapter<IFilter> adapter =
        new ArrayAdapter<IFilter>(
            (Activity) activity, android.R.layout.select_dialog_item, filters);
    builder.setAdapter(
        adapter,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int item) {
            runAfterwards.run(filters[item]);
          }
        });

    builder.create().show();
  }
Exemple #2
0
 public void run(Context context) {
   runnable.run(context);
 }