Example usage for android.app AlertDialog getListView

List of usage examples for android.app AlertDialog getListView

Introduction

In this page you can find the example usage for android.app AlertDialog getListView.

Prototype

public ListView getListView() 

Source Link

Document

Gets the list view used in the dialog.

Usage

From source file:org.cowboycoders.cyclisimo.fragments.ChooseActivityDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    activity = getActivity();//from w ww. j  a  v  a  2  s .co  m
    packageManager = activity.getPackageManager();
    List<DisplayInfo> displayInfos = getDisplayInfos();

    ArrayAdapter<DisplayInfo> arrayAdapter = new ArrayAdapter<DisplayInfo>(activity,
            R.layout.choose_activity_list_item, R.id.choose_activity_list_item_text1, displayInfos) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view;
            if (convertView == null) {
                view = activity.getLayoutInflater().inflate(R.layout.choose_activity_list_item, parent, false);
            } else {
                view = convertView;
            }
            DisplayInfo displayInfo = getItem(position);
            TextView text1 = (TextView) view.findViewById(R.id.choose_activity_list_item_text1);
            TextView text2 = (TextView) view.findViewById(R.id.choose_activity_list_item_text2);
            ImageView icon = (ImageView) view.findViewById(R.id.choose_activity_list_item_icon);
            text1.setText(displayInfo.primaryLabel);
            if (displayInfo.secondaryLabel != null) {
                text2.setVisibility(View.VISIBLE);
                text2.setText(displayInfo.secondaryLabel);
            } else {
                text2.setVisibility(View.GONE);
            }
            icon.setImageDrawable(displayInfo.icon);
            return view;
        }
    };
    return new AlertDialog.Builder(activity)
            .setSingleChoiceItems(arrayAdapter, 0, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    AlertDialog alertDialog = (AlertDialog) dialog;
                    DisplayInfo displayInfo = (DisplayInfo) alertDialog.getListView().getItemAtPosition(which);
                    ActivityInfo activityInfo = displayInfo.resolveInfo.activityInfo;
                    String packageName = activityInfo.applicationInfo.packageName;
                    String className = activityInfo.name;

                    long trackId = getArguments().getLong(KEY_TRACK_ID);
                    String trackUrl = getArguments().getString(KEY_TRACK_URL);
                    if (trackUrl == null) {
                        SendRequest sendRequest = new SendRequest(trackId);
                        sendRequest.setSendMaps(true);
                        sendRequest.setNewMap(true);
                        sendRequest.setSharingAppPackageName(packageName);
                        sendRequest.setSharingAppClassName(className);
                        Intent intent = IntentUtils.newIntent(activity, ConfirmSharingActivity.class)
                                .putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest);
                        startActivity(intent);
                        dismiss();
                    } else {
                        Intent intent = IntentUtils.newShareUrlIntent(activity, trackId, trackUrl, packageName,
                                className);
                        startActivity(intent);
                        activity.finish();
                    }
                }
            }).setTitle(R.string.share_track_picker_title).create();
}

From source file:org.mythdroid.activities.MDActivity.java

/** Create a dialog allowing user to choose default frontend */
private Dialog createFrontendDialog() {

    final AlertDialog d = new AlertDialog.Builder(ctx).setItems(new String[] {}, null)
            .setIcon(drawable.ic_menu_upload_you_tube).setTitle(R.string.chFe).create();

    d.getListView().setOnItemClickListener(new OnItemClickListener() {
        @Override/*from ww  w .  j  av  a 2 s .com*/
        public void onItemClick(AdapterView<?> av, View v, int pos, long id) {
            onHere = false;
            String fe = (String) av.getAdapter().getItem(pos);
            Globals.curFe = fe;
            updateFrontendIndicator();
            if (fe.equals(Messages.getString("MDActivity.0"))) // Here //$NON-NLS-1$
                onHere = true;
            d.dismiss();
        }
    });

    return d;
}

From source file:com.simas.vc.file_chooser.FileChooser.java

@NonNull
@Override/*  w w w.j a  va  2  s.  c  o m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    mAdapter = new FileChooserAdapter();
    AlertDialog dialog = new AlertDialog.Builder(getActivity()).setAdapter(mAdapter, null).create();

    /* Configure the dialog */
    // Back listener
    dialog.setOnKeyListener(this);

    // Item click listener
    dialog.getListView().setOnItemClickListener(this);

    // Add header (up navigation) // Do it with the adapter removed, so lower APIs don't crash!
    dialog.getListView().setAdapter(null);
    View header = createHeader(dialog.getListView());
    dialog.getListView().addHeaderView(header);
    dialog.getListView().setAdapter(mAdapter);

    // Show sub-files
    mAdapter.setFiles(getSubFiles(sCurrentPath));

    return dialog;
}

From source file:com.openerp.addons.note.EditNoteFragment.java

public void openTagList() {

    AlertDialog.Builder builder = new AlertDialog.Builder(scope.context());
    note_tags = db.getAllNoteTags();/* w w  w.  j  a v  a  2s  .c  o m*/
    ArrayList<String> keyList = new ArrayList<String>(note_tags.keySet());

    if (keyList.size() > 0) {
        stringArray = new String[keyList.size() - 1];
        stringArray = keyList.toArray(stringArray);

        builder.setTitle("");
        builder.setMultiChoiceItems(stringArray, null, new DialogInterface.OnMultiChoiceClickListener() {
            public void onClick(DialogInterface dialog, int item, boolean isChecked) {
            }
        });

        builder.setPositiveButton("", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                AlertDialog d = (AlertDialog) dialog;
                ListView v = d.getListView();
                int i = 0;
                while (i < stringArray.length) {
                    if (v.isItemChecked(i)) {
                        Integer id = Integer
                                .parseInt(note_tags.get(v.getItemAtPosition(i).toString()).toString());

                        if (!selectedTags.containsKey(note_tags.get(v.getItemAtPosition(i).toString()))) {
                            noteTags.addObject(new TagsItems(id, stringArray[i], ""));
                        }
                    }
                    i++;
                }
            }
        });
    } else {
        builder.setTitle(" \n");
    }

    builder.setNegativeButton("?", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface di, int i) {
        }
    });

    builder.setNeutralButton("", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            createNotetag();
        }
    });

    final Dialog dialog = builder.create();
    dialog.show();
}

From source file:com.thatkawaiiguy.meleehandbook.activity.SearchResultsActivity.java

private void showDialog() {
    AlertDialog dialog;/*w  ww. j a  v  a  2  s.  c  o  m*/

    checked = new boolean[] { prefs.getBoolean(TECH_KEY, true), prefs.getBoolean(CHAR_KEY, true),
            prefs.getBoolean(FUN_KEY, true), prefs.getBoolean(MAP_KEY, true), prefs.getBoolean(TERM_KEY, true),
            prefs.getBoolean(UNIQUE_KEY, true) };

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Select which list items you want to appear");
    builder.setMultiChoiceItems(R.array.filter_options, checked,
            new DialogInterface.OnMultiChoiceClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) {
                    AlertDialog d = (AlertDialog) dialog;
                    ListView v = d.getListView();
                    int i = 0;
                    while (i < checked.length) {
                        v.setItemChecked(i, checked[i]);
                        i++;
                    }
                    checked[indexSelected] = isChecked;
                }
            }).setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    prefs.edit().putBoolean(TECH_KEY, checked[0]).apply();
                    prefs.edit().putBoolean(CHAR_KEY, checked[1]).apply();
                    prefs.edit().putBoolean(FUN_KEY, checked[2]).apply();
                    prefs.edit().putBoolean(MAP_KEY, checked[3]).apply();
                    prefs.edit().putBoolean(TERM_KEY, checked[4]).apply();
                    prefs.edit().putBoolean(UNIQUE_KEY, checked[5]).apply();
                    checked = new boolean[] { prefs.getBoolean(TECH_KEY, true),
                            prefs.getBoolean(CHAR_KEY, true), prefs.getBoolean(FUN_KEY, true),
                            prefs.getBoolean(MAP_KEY, true), prefs.getBoolean(TERM_KEY, true),
                            prefs.getBoolean(UNIQUE_KEY, true) };
                    search(query);
                }
            }).setNegativeButton("Cancel", null);

    dialog = builder.create();//AlertDialog dialog; create like this outside onClick
    dialog.show();
}

From source file:org.mythdroid.activities.Main.java

private Dialog createMddDialog() {

    final AlertDialog d = new AlertDialog.Builder(ctx).setItems(new String[] {}, null)
            .setIcon(drawable.ic_menu_agenda).setTitle(R.string.mddCmd).create();

    d.getListView().setOnItemClickListener(new OnItemClickListener() {
        @Override// w  w w  . j  a va  2  s.  c om
        public void onItemClick(AdapterView<?> av, View v, int pos, long id) {
            try {
                MDDManager.mddCommand(Globals.getFrontend(ctx).addr, (String) av.getItemAtPosition(pos));
            } catch (IOException e) {
                ErrUtil.postErr(ctx, e);
            }
            d.dismiss();
        }
    });

    return d;

}

From source file:org.mythdroid.activities.Main.java

private Dialog createWakeDialog() {

    final AlertDialog d = new AlertDialog.Builder(ctx).setItems(new String[] {}, null)
            .setIcon(drawable.ic_lock_power_off).setTitle(R.string.wakeFe).create();

    d.getListView().setOnItemClickListener(new OnItemClickListener() {
        @Override/*  w  w w .  ja  va  2  s.c o  m*/
        public void onItemClick(AdapterView<?> av, View v, int pos, long id) {
            String name = (String) av.getAdapter().getItem(pos);
            try {
                WakeOnLan.wake(DatabaseUtil.getFrontendHwAddr(ctx, name));
                Globals.curFe = name;
            } catch (Exception e) {
                ErrUtil.err(ctx, e);
            }
            d.dismiss();
        }
    });

    return d;

}

From source file:org.mythdroid.activities.Main.java

private Dialog createGuideDialog() {

    final AlertDialog d = new AlertDialog.Builder(ctx).setItems(new String[] {}, null)
            .setIcon(drawable.ic_menu_upload_you_tube).setTitle(R.string.dispGuide).create();

    d.getListView().setOnItemClickListener(new OnItemClickListener() {
        @Override//  w ww . j av  a  2 s .  c o m
        public void onItemClick(AdapterView<?> av, View v, int pos, long id) {

            String item = (String) av.getItemAtPosition(pos);
            d.dismiss();

            if (item.equals(Messages.getString("MDActivity.0"))) { //$NON-NLS-1$
                // Here
                startActivity(new Intent().setClass(ctx, Guide.class));
                return;
            }

            else if (item.equals(Messages.getString("MythDroid.23"))) { //$NON-NLS-1$
                // Choose frontend
                nextActivity = NavRemote.class;
                setExtra(Extras.GUIDE.toString());
                showDialog(FRONTEND_CHOOSER);
                return;
            }

            else {
                startActivity(
                        new Intent().putExtra(Extras.GUIDE.toString(), true).setClass(ctx, NavRemote.class));
                return;
            }

        }
    });

    return d;
}

From source file:com.cliff.comichelper.MainActivity.java

protected void showSelectVolumesDialog(final Comic comic) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.title_select_volumes);
    ArrayList<String> list = new ArrayList<String>();
    for (int i = 0; i < comic.volumes.length; i++)
        list.add(comic.volumes[i].volumeName);

    builder.setMultiChoiceItems(list.toArray(new CharSequence[list.size()]), null,
            new DialogInterface.OnMultiChoiceClickListener() {
                @Override//w  ww  .j av  a  2s  .  c  om
                public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) {
                }
            })
            // Set the action buttons
            .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    allowCloseDialog(dialog, true);
                    final AlertDialog alert = (AlertDialog) dialog;
                    final ListView list = alert.getListView();
                    ArrayList<Integer> intList = new ArrayList<Integer>();
                    for (int i = 0; i < list.getAdapter().getCount(); i++) {
                        if (list.isItemChecked(i))
                            intList.add(i);
                    }
                    int[] volumes = new int[intList.size()];
                    for (int i = 0; i < volumes.length; i++)
                        volumes[i] = intList.get(i);
                    Command command = new Command(Constants.COMMAND_DOWNLOAD);
                    command.addParam(Constants.PARAM_COMIC, comic);
                    command.addParam(Constants.PARAM_VOLUMES, volumes);
                    command.addParam(Constants.PARAM_ROOTDIR, preferences
                            .getString(SettingsActivity.KEY_DOWNLOAD_LOCATION, SettingsActivity.DIR_DOWNLOAD));
                    eventBus.post(command);
                    startProgressDialog(R.string.title_download, R.string.message_starting, false);
                }
            }).setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    allowCloseDialog(dialog, true);
                    dialog.cancel();
                }
            }).setNeutralButton(R.string.button_selectall, new DialogInterface.OnClickListener() {
                private boolean enabled = false;

                @Override
                public void onClick(DialogInterface dialog, int id) {
                    allowCloseDialog(dialog, false);

                    final AlertDialog alert = (AlertDialog) dialog;
                    final ListView list = alert.getListView();
                    enabled = !enabled;
                    for (int i = 0; i < list.getAdapter().getCount(); i++) {
                        list.setItemChecked(i, enabled);
                    }
                }
            });

    AlertDialog dialog = builder.create();
    dialog.show();
}

From source file:com.google.android.apps.paco.ExploreDataActivity.java

private View renderMultiSelectListButton(final Long id, final TextView textview) {

    DialogInterface.OnMultiChoiceClickListener multiselectListDialogListener = new DialogInterface.OnMultiChoiceClickListener() {
        @Override/*w w w .j  av  a2 s  . com*/
        public void onClick(DialogInterface dialog, int which, boolean isChecked) {
            if (isChecked) {
                if (checkedChoices.get(id) != null) {
                    checkedChoices.get(id).add(inputIds.get(which));
                } else {
                    List<Long> tempList = new ArrayList<Long>();
                    tempList.add(inputIds.get(which));
                    checkedChoices.put(id, tempList);
                }
            } else {
                checkedChoices.get(id).remove(inputIds.get(which));
                if (checkedChoices.get(id).isEmpty())
                    checkedChoices.remove(id);
            }
        }
    };

    AlertDialog.Builder builder = new AlertDialog.Builder(mainLayout.getContext());
    builder.setTitle(R.string.make_selections);

    boolean[] checkedChoicesBoolArray = new boolean[inputIds.size()];
    int count = inputIds.size();

    if (checkedChoices.get(id) != null) {
        for (int i = 0; i < count; i++) {
            checkedChoicesBoolArray[i] = checkedChoices.get(id).contains(inputIds.get(i));
        }
    }
    String[] listChoices = new String[inputIds.size()];
    inpNames.toArray(listChoices);
    builder.setMultiChoiceItems(listChoices, checkedChoicesBoolArray, multiselectListDialogListener);
    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int whichButton) {
            getLabelWithSelectedVariables(id, textview);
        }
    });
    AlertDialog multiSelectListDialog = builder.create();
    multiSelectListDialog.show();
    return multiSelectListDialog.getListView();
}