@Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { ((AlertDialog) dialog).getListView().setItemChecked(which, isChecked); } };
/** * Simulates a click on the {@code Dialog} item indicated by {@code index}. Handles both multi- and single-choice dialogs, tracks which items are currently * checked and calls listeners appropriately. * * @param index the index of the item to click on */ public void clickOnItem(int index) { ShadowListView shadowListView = Shadow.extract(realAlertDialog.getListView()); shadowListView.performItemClick(index); }
@Override public boolean retain() { if (mDialog != null) { // Save the selection state of each list item mSelection = mDialog.getListView().getCheckedItemPositions(); mDialog.dismiss(); mDialog = null; return true; } return false; }
@Override public void onClick(DialogInterface dialog, int which) { ListView listView = ((AlertDialog) dialog).getListView(); SparseBooleanArray pos = listView.getCheckedItemPositions(); boolean includeGlobals = mImportContents.globalSettings && pos.get(0); List<String> accountUuids = new ArrayList<>(); int start = mImportContents.globalSettings ? 1 : 0; for (int i = start, end = listView.getCount(); i < end; i++) { if (pos.get(i)) { accountUuids.add(mImportContents.accounts.get(i - start).uuid); } } /* * TODO: Think some more about this. Overwriting could change the store * type. This requires some additional code in order to work smoothly * while the app is running. */ boolean overwrite = false; dialog.dismiss(); activity.setNonConfigurationInstance(null); ImportAsyncTask importAsyncTask = new ImportAsyncTask(activity, includeGlobals, accountUuids, overwrite, mUri); activity.setNonConfigurationInstance(importAsyncTask); importAsyncTask.execute(); } });
ListView lv = dialog.getListView(); // this is a ListView with your "buds" in it lv.setOnItemLongClickListener((parent, view, position, id) -> { dialog.dismiss();
@Config(sdk = 21) @Test public void testRemoveAccount() { AccountManager.get(activity).addAccountExplicitly(new Account("existing", BuildConfig.APPLICATION_ID), "password", null); Preferences.setUsername(activity, "existing"); drawerAccount.performClick(); AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog(); assertNotNull(alertDialog); assertThat(alertDialog.getListView().getAdapter()).hasCount(1); alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL).performClick(); assertThat(alertDialog).isNotShowing(); assertThat(AccountManager.get(activity).getAccounts()).isEmpty(); }
@Test public void testExistingAccount() { AccountManager.get(activity).addAccountExplicitly(new Account("existing", BuildConfig.APPLICATION_ID), "password", null); drawerAccount.performClick(); AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog(); assertNotNull(alertDialog); assertThat(alertDialog.getListView().getAdapter()).hasCount(1); shadowOf(alertDialog).clickOnItem(0); alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick(); assertThat(alertDialog).isNotShowing(); assertThat(drawerAccount).hasText("existing"); assertThat(drawerLogout).isVisible(); drawerAccount.performClick(); alertDialog = ShadowAlertDialog.getLatestAlertDialog(); assertThat(alertDialog.getListView().getAdapter()).hasCount(1); }
AlertDialog alertDialogObject = dialogBuilder.create(); ListView listView=alertDialogObject.getListView(); listView.setDivider(new ColorDrawable(Color.BLUE)); // set color listView.setDividerHeight(2); // set height alertDialogObject.show();
@Test public void testAddAccount() { AccountManager.get(activity).addAccountExplicitly(new Account("existing", BuildConfig.APPLICATION_ID), "password", null); drawerAccount.performClick(); AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog(); assertNotNull(alertDialog); assertThat(alertDialog.getListView().getAdapter()).hasCount(1); alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick(); assertThat(alertDialog).isNotShowing(); ((ShadowSupportDrawerLayout) Shadow.extract(activity.findViewById(R.id.drawer_layout))) .getDrawerListeners().get(0) .onDrawerClosed(activity.findViewById(R.id.drawer)); assertThat(shadowOf(activity).getNextStartedActivity()) .hasComponent(activity, LoginActivity.class); }
int position = alert.getListView().getCheckedItemPosition();
AlertDialog alert = builder.create(); alert.getListView().setSelector(R.drawable.listview_selector); alert.getListView().setBackgroundColor(Color.RED); alert.getListView().invalidate(); alert.show();
@Override protected void onPrepareDialog(int id, Dialog dialog) { switch (id) { case DIALOG_REVIEW: ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this, android.R.layout.select_dialog_singlechoice, android.R.id.text1, phoneNums); AlertDialog ad = (AlertDialog) dialog; ad.getListView().setAdapter(adapter); break; default: super.onPrepareDialog(id, dialog); } }
AlertDialog alertDialog = builder.create(); ListView listView = alertDialog.getListView(); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub } });
public void showTrackModel(final TextView textView){ RadioOnClick OnClick = new RadioOnClick(textView); AlertDialog ad =new Builder(activity).setTitle(activity.getResources().getString(R.string.trackig_mode)) .setSingleChoiceItems(R.array.trackig_mode_array,OnClick.getIndex(),OnClick).create(); ListView areaListView=ad.getListView(); ad.show(); }
@Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); int selectedPosition = ((AlertDialog)dialogInterface).getListView().getCheckedItemPosition(); selectedElements.add(selectedFormElement.getOptions().get(selectedPosition)); selectedFormElement.setOptionsSelected(selectedElements); selectedEditText.setText(selectedFormElement.getOptionsSelected().toString()); } });
/** * Simulates a click on the {@code Dialog} item indicated by {@code index}. Handles both multi- and single-choice dialogs, tracks which items are currently * checked and calls listeners appropriately. * * @param index the index of the item to click on */ public void clickOnItem(int index) { Shadows.shadowOf(realAlertDialog.getListView()).performItemClick(index); }
/** * Simulates a click on the {@code Dialog} item indicated by {@code index}. Handles both multi- and single-choice dialogs, tracks which items are currently * checked and calls listeners appropriately. * * @param index the index of the item to click on */ public void clickOnItem(int index) { ShadowListView shadowListView = Shadow.extract(realAlertDialog.getListView()); shadowListView.performItemClick(index); }
private static final int specialItem = ...; public void onClick(DialogInterface dialog, int which, boolean isChecked) { if (which == singleItem) { // only if they clicked 'none' final AlertDialog alertDialog = (AlertDialog) dialog; final ListView alertDialogList = alertDialog.getListView(); for (int position = 0; position < alertDialogList.getChildCount(); position++) { if (position != which) { alertDialogList.getChildAt(position).setEnabled(!isChecked); } } } }
@Override public void onDismiss(DialogInterface dialog) { ListView list = ((AlertDialog)dialog).getListView(); int which = list.getCheckedItemPosition(); CheckBox reverseSort = (CheckBox)list.findViewById(R.id.reverse_sort); if (reverseSort.isChecked()) { which = ~which; } mPagerAdapter.setSortMode(which); }
@Override public void onClick(DialogInterface dialogInterface, int selectedOption) { int selectedPosition = ((AlertDialog) dialogInterface).getListView().getCheckedItemPosition(); Log.e("Option", " " + selectedPosition); if (option.equals(OPTION_VIDEO_ENCODER)) { getPresenter().onChangeVideoEncoder(selectedPosition); } else if (option.equals(OPTION_RESOLUTION)) { getPresenter().onChangeResolution(selectedPosition); } } })