本文整理汇总了Java中android.widget.Button类的典型用法代码示例。如果您正苦于以下问题:Java Button类的具体用法?Java Button怎么用?Java Button使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Button类属于android.widget包,在下文中一共展示了Button类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.widget.Button; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.title_editor);
// Get the uri of the note whose title we want to edit
mUri = getIntent().getData();
// Get a cursor to access the note
mCursor = managedQuery(mUri, PROJECTION, null, null, null);
// Set up click handlers for the text field and button
mText = (EditText) this.findViewById(R.id.title);
mText.setOnClickListener(this);
Button b = (Button) findViewById(R.id.ok);
b.setOnClickListener(this);
}
示例2: RunwiseDialog
import android.widget.Button; //导入依赖的package包/类
@Inject
public RunwiseDialog(@ActivityContext Context context) {
super(context, R.style.CustomProgressDialog);
setContentView(R.layout.dialog_layout);
Window window = getWindow();
window.getAttributes().gravity = Gravity.CENTER;
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
this.setCancelable(true);
this.setCanceledOnTouchOutside(false);
this.context = (TextView) this.findViewById(R.id.context);
cancle = (Button) this.findViewById(R.id.cancle);
okBtn = (Button) this.findViewById(R.id.ok);
vLine = this.findViewById(R.id.vline);
hLine = this.findViewById(R.id.hline);
title = (TextView) this.findViewById(R.id.title);
btnLayout = (LinearLayout) this.findViewById(R.id.dialog_btn_layout);
setLeftBtnListener("取消",null);
}
示例3: convert
import android.widget.Button; //导入依赖的package包/类
@Override
protected void convert(BaseViewHolder viewHolder, final Wares wares) {
SimpleDraweeView draweeView = (SimpleDraweeView) viewHolder.getView(R.id.drawee_view);
draweeView.setImageURI(Uri.parse(wares.getImgUrl()));
viewHolder.getTextView(R.id.text_title).setText(wares.getName());
viewHolder.getTextView(R.id.text_price).setText("¥ "+wares.getPrice());
Button button =viewHolder.getButton(R.id.btn_add);
if(button !=null) {
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
provider.put(wares);
ToastUtils.show(context, "已添加到购物车");
}
});
}
}
示例4: onSuccess
import android.widget.Button; //导入依赖的package包/类
@Override
public void onSuccess(com.facebook.login.LoginResult loginResult) {
Profile facebookProfile = Profile.getCurrentProfile();
if (facebookProfile == null) {
String errorMsg = InfoFromFacebookActivity.this.getResources().getString(R.string.facebook_error);
errorMsg = errorMsg + ".";
Snackbar.make(textViewFacebookName, errorMsg, Snackbar.LENGTH_LONG).show();
textViewFacebookName.setText(errorMsg);
} else {
facebookProfilePhoto.setProfileId(facebookProfile.getId());
textViewFacebookName.setText(facebookProfile.getName());
buttonAck.setEnabled(true);
buttonSwitch.setVisibility(Button.VISIBLE);
}
// TODO: Do not store access token - it is a security issue storing this
// TODO and appears to be of no benefit.
// AccessToken token = loginResult.getAccessToken();
// DataHolder data = DataHolder.getInstance(InfoFromFacebookActivity.this.getApplicationContext());
// data.setFacebookToken(token.getToken());
// data.persist();
}
示例5: showAbout
import android.widget.Button; //导入依赖的package包/类
/**
* Display About dialog
*/
private void showAbout() {
final AlertDialog dialog = showAlert(MainActivity.this,
getString(R.string.app_name),
R.layout.about,
R.drawable.ic_ulogger_logo_24dp);
final TextView versionLabel = (TextView) dialog.findViewById(R.id.about_version);
versionLabel.setText(getString(R.string.about_version, BuildConfig.VERSION_NAME));
final TextView descriptionLabel = (TextView) dialog.findViewById(R.id.about_description);
final TextView description2Label = (TextView) dialog.findViewById(R.id.about_description2);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
descriptionLabel.setText(fromHtmlDepreciated(getString(R.string.about_description)));
description2Label.setText(fromHtmlDepreciated(getString(R.string.about_description2)));
} else {
descriptionLabel.setText(Html.fromHtml(getString(R.string.about_description), android.text.Html.FROM_HTML_MODE_LEGACY));
description2Label.setText(Html.fromHtml(getString(R.string.about_description2), android.text.Html.FROM_HTML_MODE_LEGACY));
}
final Button okButton = (Button) dialog.findViewById(R.id.about_button_ok);
okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
}
示例6: build
import android.widget.Button; //导入依赖的package包/类
public EmptyView build(){
if(parent == null)
throw new IllegalArgumentException("No parent viewGroup");
emptyView.view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.empty_view, parent, false);
TextView textView = ButterKnife.findById(emptyView.view, R.id.text_empty_hint);
textView.setText(emptyHint);
Button button = ButterKnife.findById(emptyView.view, R.id.btn_empty_view);
button.setText(buttonText);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(mOnClickListener != null)
mOnClickListener.onClick(v);
}
});
parent.addView(emptyView.view);
return emptyView;
}
示例7: updateUI
import android.widget.Button; //导入依赖的package包/类
private void updateUI() {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
final Button button = (Button) getView().findViewById(R.id.connectButton);
if (!InstagramClient.instance().isAuthenticated()) {
button.setText(getString(R.string.login));
button.setOnClickListener(new LoginClickListener());
} else {
button.setText(getString(R.string.logout));
button.setOnClickListener(new LogoutClickListener(button));
}
}
});
}
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:17,代码来源:InstagramPreferencesFragment.java
示例8: onCreate
import android.widget.Button; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.range_picker_activity);
CalendarView calendarView = (CalendarView) findViewById(R.id.calendarView);
Button getDateButton = (Button) findViewById(R.id.getDateButton);
getDateButton.setOnClickListener(v -> {
for (Calendar calendar : calendarView.getSelectedDates()) {
System.out.println(calendar.getTime().toString());
Toast.makeText(getApplicationContext(),
calendar.getTime().toString(),
Toast.LENGTH_SHORT).show();
}
});
}
示例9: onCreateView
import android.widget.Button; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_exit, container, false);
mSharedPreferences = getActivity().getSharedPreferences(
"org.greenstand.android", Context.MODE_PRIVATE);
Button yesBtn = (Button) v.findViewById(R.id.fragment_exit_yes);
yesBtn.setOnClickListener(ExitFragment.this);
Button noBtn = (Button) v.findViewById(R.id.fragment_exit_no);
noBtn.setOnClickListener(ExitFragment.this);
return v;
}
示例10: setUp
import android.widget.Button; //导入依赖的package包/类
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
changePasswordActivity =
Robolectric.setupActivity(TestChangePasswordActivity.class);
passwordConfirmationWrapper = (TextInputLayout) changePasswordActivity
.findViewById(R.id.new_password_confirm_wrapper);
currentPassword = (EditText) changePasswordActivity
.findViewById(R.id.current_password_entry);
newPassword = (EditText) changePasswordActivity
.findViewById(R.id.new_password_entry);
newPasswordConfirmation = (EditText) changePasswordActivity
.findViewById(R.id.new_password_confirm);
strengthMeter = (StrengthMeter) changePasswordActivity
.findViewById(R.id.strength_meter);
changePasswordButton = (Button) changePasswordActivity
.findViewById(R.id.change_password);
}
示例11: initDeleteButton
import android.widget.Button; //导入依赖的package包/类
protected void initDeleteButton(Button button, final Post post) {
if (post.own) {
button.setVisibility(0);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (AccountUtils.isVisitorAccount(BaseTimelineAdapter.this.activity)) {
CheckAccountPopwindow.showVisitorPopWindow(BaseTimelineAdapter.this
.activity);
} else {
BaseTimelineAdapter.this.showDeleteDialog(post);
}
}
});
return;
}
button.setVisibility(8);
}
示例12: onCreate
import android.widget.Button; //导入依赖的package包/类
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
setContentView(R.layout.confirm_delete);
getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT);
activity = this;
mPrompt = (TextView) findViewById(R.id.prompt);
mButton = (Button) findViewById(R.id.delete);
mButton.setOnClickListener(mButtonClicked);
(findViewById(R.id.cancel)).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});
mPrompt.setText(getString(R.string.clear_online_dialog));
}
示例13: displayYoutubeIdDialog
import android.widget.Button; //导入依赖的package包/类
private void displayYoutubeIdDialog(@NonNull ArrayList<YoutubeVideoData> youtubeVideoDataList) {
final Dialog dialog = new Dialog(_context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_listview);
TextView title = dialog.findViewById(R.id.dialog_title_text_view);
title.setText(_context.getResources().getString(R.string.select_youtube_video));
final YoutubeVideoListAdapter listAdapter = new YoutubeVideoListAdapter(_context, youtubeVideoDataList, dialog::dismiss);
ListView listView = dialog.findViewById(R.id.dialog_list_view);
listView.setAdapter(listAdapter);
listView.setVisibility(View.VISIBLE);
Button closeButton = dialog.findViewById(R.id.dialog_button_close);
closeButton.setOnClickListener(view -> dialog.dismiss());
dialog.setCancelable(true);
dialog.show();
Window window = dialog.getWindow();
if (window != null) {
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
} else {
Logger.getInstance().Warning(TAG, "Window is null!");
}
}
示例14: ViewHolder
import android.widget.Button; //导入依赖的package包/类
public ViewHolder(final View itemView) {
super(itemView);
followRequestee = (TextView) itemView.findViewById(R.id.followRequesteeName);
approveButton = (Button) itemView.findViewById(R.id.approveButton);
declineButton = (Button) itemView.findViewById(R.id.declineButton);
// listens when an item is clicked
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION) {
listener.onItemClick(itemView, position);
}
}
}
});
}
示例15: initViews
import android.widget.Button; //导入依赖的package包/类
private void initViews() {
latitudeInput = (EditText) findViewById(R.id.latitude_input);
longitudeInput = (EditText) findViewById(R.id.longitude_input);
mockLocationView = (TextView) findViewById(R.id.mock_location_view);
updatedLocationView = (TextView) findViewById(R.id.updated_location_view);
mockModeToggleButton = (ToggleButton) findViewById(R.id.toggle_button);
setLocationButton = (Button) findViewById(R.id.set_location_button);
mockModeToggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
setMockMode(isChecked);
setLocationButton.setEnabled(isChecked);
}
});
setLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addMockLocation();
}
});
}