本文整理了Java中android.widget.Button.performClick()
方法的一些代码示例,展示了Button.performClick()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Button.performClick()
方法的具体详情如下:
包路径:android.widget.Button
类名称:Button
方法名:performClick
暂无
代码示例来源:origin: qiujuer/Genius-Android
@Override
public boolean performClick() {
final TouchEffectDrawable d = mTouchDrawable;
if (d != null) {
return d.performClick(this) && super.performClick();
} else
return super.performClick();
}
代码示例来源:origin: seven332/EhViewer
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (mDialog != null) {
Button button = mDialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.performClick();
}
return true;
} else {
return false;
}
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void clickingPositiveButtonDismissesDialog() throws Exception {
AlertDialog alertDialog = new AlertDialog.Builder(application)
.setPositiveButton("Positive", null).create();
alertDialog.show();
assertTrue(alertDialog.isShowing());
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).performClick();
assertFalse(alertDialog.isShowing());
}
代码示例来源:origin: robolectric/robolectric
@Test
public void clickingNegativeButtonDismissesDialog() throws Exception {
AlertDialog alertDialog = new AlertDialog.Builder(application)
.setNegativeButton("Negative", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).create();
alertDialog.show();
assertTrue(alertDialog.isShowing());
alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).performClick();
assertFalse(alertDialog.isShowing());
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldNotExplodeWhenNestingAlerts() throws Exception {
final Activity activity = Robolectric.buildActivity(Activity.class).create().get();
final AlertDialog nestedDialog = new AlertDialog.Builder(activity)
.setTitle("Dialog 2")
.setMessage("Another dialog")
.setPositiveButton("OK", null)
.create();
final AlertDialog dialog = new AlertDialog.Builder(activity)
.setTitle("Dialog 1")
.setMessage("A dialog")
.setPositiveButton("Button 1", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
nestedDialog.show();
}
}).create();
dialog.show();
assertThat(ShadowDialog.getLatestDialog()).isEqualTo(dialog);
dialog.getButton(Dialog.BUTTON_POSITIVE).performClick();
assertThat(ShadowDialog.getLatestDialog()).isEqualTo(nestedDialog);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void clickingNeutralButtonDismissesDialog() throws Exception {
AlertDialog alertDialog = new AlertDialog.Builder(application)
.setNeutralButton("Neutral", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).create();
alertDialog.show();
assertTrue(alertDialog.isShowing());
alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL).performClick();
assertFalse(alertDialog.isShowing());
}
代码示例来源:origin: hidroh/materialistic
@Test
public void testOptionsMenuClear() {
assertTrue(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_clear).isVisible());
shadowOf(activity).clickMenuItem(R.id.menu_clear);
AlertDialog dialog = ShadowAlertDialog.getLatestAlertDialog();
dialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick();
assertEquals(2, adapter.getItemCount());
shadowOf(activity).clickMenuItem(R.id.menu_clear);
dialog = ShadowAlertDialog.getLatestAlertDialog();
dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
verify(favoriteManager).clear(any(Context.class), any());
when(favoriteManager.getSize()).thenReturn(0);
observerCaptor.getValue().onChanged();
assertEquals(0, adapter.getItemCount());
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testOnClickAttribute() throws Exception {
ClickActivity activity = buildActivity(ClickActivity.class).create().get();
assertThat(activity.clicked).isFalse();
Button button = activity.findViewById(R.id.button);
button.performClick();
assertThat(activity.clicked).isTrue();
}
代码示例来源:origin: hidroh/materialistic
@Test
public void testClearRecentSearches() {
ShadowSearchRecentSuggestions.historyClearCount = 0;
assertNotNull(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_clear_recent));
shadowOf(activity).clickMenuItem(R.id.menu_clear_recent);
AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
assertNotNull(alertDialog);
alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
assertEquals(1, ShadowSearchRecentSuggestions.historyClearCount);
}
代码示例来源:origin: robolectric/robolectric
/** Perform the 'traditional' mechanism of clicking a button in Robolectric using findViewById */
@Test
@UiThreadTest
public void buttonClick() throws Exception {
EspressoActivity activity = activityRule.getActivity();
Button button = activity.findViewById(R.id.button);
button.performClick();
assertThat(activity.buttonClicked).isTrue();
}
代码示例来源:origin: hidroh/materialistic
@Test
public void testSubmitFailed() {
((EditText) activity.findViewById(R.id.edittext_title)).setText("title");
((EditText) activity.findViewById(R.id.edittext_content)).setText("http://example.com");
shadowOf(activity).clickMenuItem(R.id.menu_send);
ShadowAlertDialog.getLatestAlertDialog().getButton(DialogInterface.BUTTON_POSITIVE)
.performClick();
verify(userServices).submit(any(Context.class), eq("title"), eq("http://example.com"),
eq(true), submitCallback.capture());
submitCallback.getValue().onDone(false);
assertThat(shadowOf(activity).getNextStartedActivity())
.hasComponent(activity, LoginActivity.class);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testInvalidOnClickAttribute() throws Exception {
Activity activity = buildActivity(Activity.class).create().get();
activity.setContentView(R.layout.with_invalid_onclick);
Button button = activity.findViewById(R.id.invalid_onclick_button);
IllegalStateException exception = null;
try {
button.performClick();
} catch (IllegalStateException e) {
exception = e;
}
assertNotNull(exception);
assertThat(exception.getMessage())
.named("The error message should contain the id name of the faulty button")
.contains("invalid_onclick_button");
}
代码示例来源:origin: hidroh/materialistic
@Test
public void testExitSaveDraft() {
((EditText) activity.findViewById(R.id.edittext_body)).setText("Reply");
shadowOf(activity).clickMenuItem(android.R.id.home);
AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
assertNotNull(alertDialog);
alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
assertThat(activity).isFinishing();
assertThat(Preferences.getDraft(activity, "1")).contains("Reply");
}
代码示例来源:origin: hidroh/materialistic
@Test
public void testExitDiscardDraft() {
((EditText) activity.findViewById(R.id.edittext_body)).setText("Reply");
shadowOf(activity).clickMenuItem(android.R.id.home);
AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
assertNotNull(alertDialog);
alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick();
assertThat(activity).isFinishing();
assertThat(Preferences.getDraft(activity, "1")).isNullOrEmpty();
}
代码示例来源:origin: googlesamples/easypermissions
@Test
public void shouldNegativeListener_whenClickingPositiveButtonFromActivity() {
AlertDialog alertDialog = new AppSettingsDialog.Builder(spyActivity)
.setTitle(TITLE)
.setRationale(RATIONALE)
.setPositiveButton(POSITIVE)
.setNegativeButton(NEGATIVE)
.setThemeResId(R.style.Theme_AppCompat)
.build()
.showDialog(positiveListener, negativeListener);
Button positive = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
positive.performClick();
verify(negativeListener, times(1))
.onClick(any(DialogInterface.class), anyInt());
}
代码示例来源:origin: googlesamples/easypermissions
@Test
public void shouldPositiveListener_whenClickingPositiveButtonFromSupportFragment() {
AlertDialog alertDialog = new AppSettingsDialog.Builder(spyFragment)
.setTitle(TITLE)
.setRationale(RATIONALE)
.setPositiveButton(POSITIVE)
.setNegativeButton(NEGATIVE)
.setThemeResId(R.style.Theme_AppCompat)
.build()
.showDialog(positiveListener, negativeListener);
Button positive = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
positive.performClick();
verify(positiveListener, times(1))
.onClick(any(DialogInterface.class), anyInt());
}
代码示例来源:origin: googlesamples/easypermissions
@Test
public void shouldPositiveListener_whenClickingPositiveButtonFromActivity() {
AlertDialog alertDialog = new AppSettingsDialog.Builder(spyActivity)
.setTitle(TITLE)
.setRationale(RATIONALE)
.setPositiveButton(POSITIVE)
.setNegativeButton(NEGATIVE)
.setThemeResId(R.style.Theme_AppCompat)
.build()
.showDialog(positiveListener, negativeListener);
Button positive = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
positive.performClick();
verify(positiveListener, times(1))
.onClick(any(DialogInterface.class), anyInt());
}
代码示例来源:origin: googlesamples/easypermissions
@Test
public void shouldNegativeListener_whenClickingPositiveButtonFromSupportFragment() {
AlertDialog alertDialog = new AppSettingsDialog.Builder(spyFragment)
.setTitle(TITLE)
.setRationale(RATIONALE)
.setPositiveButton(POSITIVE)
.setNegativeButton(NEGATIVE)
.setThemeResId(R.style.Theme_AppCompat)
.build()
.showDialog(positiveListener, negativeListener);
Button positive = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
positive.performClick();
verify(negativeListener, times(1))
.onClick(any(DialogInterface.class), anyInt());
}
代码示例来源:origin: hidroh/materialistic
@Test
public void testOnBackPressed() {
shadowOf(activity).clickMenuItem(android.R.id.home);
AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
assertNotNull(alertDialog);
alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
assertThat(activity).isFinishing();
}
代码示例来源:origin: hidroh/materialistic
@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();
}
内容来源于网络,如有侵权,请联系作者删除!