@Override public void onDialogPositiveClick(DialogFragment dialog) { // User pressed OK, so we need to grab the values from the // dialog's fields and apply them to the Views in the Main // Activity // Start with the payment amount Dialog dialogView = dialog.getDialog(); EditText paymentEt = (EditText) dialogView.findViewById(R.id.edittext_payment);
final Dialog dialog = new Dialog(MyActivity.this); dialog.setContentView(R.layout.custom_dialog); dialog.setTitle("Title"); Button button = (Button) dialog.findViewById(R.id.dialog_ok); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { EditText edit=(EditText)dialog.findViewById(R.id.dialog_edit); String text=edit.getText().toString(); dialog.dismiss(); name=text; } }); dialog.show();
final Dialog d = new Dialog(this,R.style.CustomDialogTheme); d.setContentView(R.layout.custom_dialog); d.show(); Button close_btn = (Button) d.findViewById(R.id.close_btn); close_btn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { d.dismiss(); } });
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.dialog) .setIcon(R.drawable.ic) .setMessage(R.string.dialog_msg); //The tricky part Dialog d = builder.show(); int dividerId = d.getContext().getResources().getIdentifier("android:id/titleDivider", null, null); View divider = d.findViewById(dividerId); divider.setBackgroundColor(getResources().getColor(R.color.my_color));
public void clickOn(int viewId) { realDialog.findViewById(viewId).performClick(); }
private void showPopup() { AlertDialog.Builder b = new AlertDialog.Builder(this); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { LayoutInflater inflater = LayoutInflater.from(this); View layout = inflater.inflate(R.layout.popup_layout, null); b.setView(layout); } else { b.setView(R.layout.popup_layout); } Dialog dlg = b.show(); dlg.findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((ListView) findViewById(R.id.list)).smoothScrollToPosition(new Random(System.currentTimeMillis()).nextInt(10)); } }); }
@Override public void onPositiveActionClicked(DialogFragment fragment) { EditText et_pass = (EditText)fragment.getDialog().findViewById(R.id.custom_et_password); Toast.makeText(mActivity, "Connected. pass=" + et_pass.getText().toString(), Toast.LENGTH_SHORT).show(); super.onPositiveActionClicked(fragment); }
private void assertThatHasExpectedButtonsAndRationale(Dialog dialog, String rationale, String positive, String negative) { TextView dialogMessage = dialog.findViewById(android.R.id.message); assertThat(dialogMessage.getText().toString()).isEqualTo(rationale); TextView positiveMessage = dialog.findViewById(android.R.id.button1); assertThat(positiveMessage.getText().toString()).isEqualTo(positive); TextView negativeMessage = dialog.findViewById(android.R.id.button2); assertThat(negativeMessage.getText().toString()).isEqualTo(negative); }
private void assertThatHasExpectedRationale(Dialog dialog, String rationale) { TextView dialogMessage = dialog.findViewById(android.R.id.message); assertThat(dialogMessage.getText().toString()).isEqualTo(rationale); }
private void assertThatHasExpectedButtonsAndRationale(Dialog dialog, String rationale, int positive, int negative) { TextView dialogMessage = dialog.findViewById(android.R.id.message); assertThat(dialogMessage.getText().toString()).isEqualTo(rationale); TextView positiveMessage = dialog.findViewById(android.R.id.button1); assertThat(positiveMessage.getText().toString()).isEqualTo(app.getString(positive)); TextView negativeMessage = dialog.findViewById(android.R.id.button2); assertThat(negativeMessage.getText().toString()).isEqualTo(app.getString(negative)); }
private void assertThatHasExpectedButtonsAndRationale(Dialog dialog, int rationale, int positive, int negative) { TextView dialogMessage = dialog.findViewById(android.R.id.message); assertThat(dialogMessage.getText().toString()).isEqualTo(app.getString(rationale)); TextView positiveMessage = dialog.findViewById(android.R.id.button1); assertThat(positiveMessage.getText().toString()).isEqualTo(app.getString(positive)); TextView negativeMessage = dialog.findViewById(android.R.id.button2); assertThat(negativeMessage.getText().toString()).isEqualTo(app.getString(negative)); }
@Test public void shouldFindViewsWithinAContentViewThatWasPreviouslySet() throws Exception { Dialog dialog = new Dialog(context); dialog.setContentView(dialog.getLayoutInflater().inflate(R.layout.main, null)); assertThat(dialog.<TextView>findViewById(R.id.title)).isInstanceOf((Class<? extends TextView>) TextView.class); }
@Test public void setContentViewWithViewAllowsFindById() throws Exception { final int viewId = 1234; final Dialog dialog = new Dialog(context); final View view = new View(context); view.setId(viewId); dialog.setContentView(view); assertSame(view, dialog.findViewById(viewId)); }
LinearLayout root = (LinearLayout) dialog.findViewById(android.R.id.list).getParent(); bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false); root.addView(bar, 0); // insert at top } else { ViewGroup root = (ViewGroup) dialog.findViewById(android.R.id.content); ListView content = (ListView) root.getChildAt(0);
LinearLayout root = (LinearLayout) dialog.findViewById(android.R.id.list).getParent(); bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false); root.addView(bar, 0); // insert at top } else { ViewGroup root = (ViewGroup) dialog.findViewById(android.R.id.content); ListView content = (ListView) root.getChildAt(0);
LinearLayout root = (LinearLayout) dialog.findViewById(android.R.id.list).getParent(); bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false); root.addView(bar, 0); // insert at top } else { ViewGroup root = (ViewGroup) dialog.findViewById(android.R.id.content); ListView content = (ListView) root.getChildAt(0);
View homeBtn = dialog.findViewById(android.R.id.home);
@Test public void testHelp() { ((PreferencesActivity.SettingsFragment) activity.getSupportFragmentManager() .findFragmentByTag(PreferencesActivity.SettingsFragment.class.getName())) .getPreferenceScreen() .findPreference(activity.getString(R.string.pref_volume_help)) .performClick(); Dialog dialog = ShadowDialog.getLatestDialog(); assertNotNull(dialog); assertThat((TextView) dialog.findViewById(R.id.alertTitle)) .hasText(R.string.pref_volume_title); }
@Test public void testLazyLoadHelp() { ((PreferencesActivity.SettingsFragment) activity.getSupportFragmentManager() .findFragmentByTag(PreferencesActivity.SettingsFragment.class.getName())) .getPreferenceScreen() .findPreference(activity.getString(R.string.pref_lazy_load_help)) .performClick(); Dialog dialog = ShadowDialog.getLatestDialog(); assertNotNull(dialog); assertThat((TextView) dialog.findViewById(R.id.alertTitle)) .hasText(R.string.pref_lazy_load_title); }
@Test public void show_shouldShowDialogThatWasAutomaticallyCreated_whenOnCreateDialogReturnsNull() throws Exception { dialogFragment.show(fragmentManager, "this is a tag"); Dialog dialog = ShadowDialog.getLatestDialog(); assertNotNull(dialog); assertSame(dialog, dialogFragment.getDialog()); assertNotNull(dialog.findViewById(R.id.title)); assertSame(dialogFragment, fragmentManager.findFragmentByTag("this is a tag")); }