Best code examples for Android Button class (android.widget.Button)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Button class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Android Button examples from Open Source projects
This code example shows how to use the following methods: setOnClickListener, setTag, setText
90:	Button mButton = new Button(mContext); 
91:	mButton.setText(aText); 
92:	mButton.setTag(Integer.toString(aCallback)); 
93:	mButton.setOnClickListener(this); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getContext, setCompoundDrawablePadding, setCompoundDrawablesWithIntrinsicBounds, setPadding, setText
81:	button.setText(buttonDef.getText()); 
-
85:	button.setPadding(0, 0, 0, 0); 
-
87:	final Drawable drawable = button.getContext().getResources().getDrawable(drawableResId); 
88:	button.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null); 
89:	button.setCompoundDrawablePadding(0); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setOnClickListener, setText
37:	Button result = new Button(context); 
38:	result.setText(name); 
39:	result.setOnClickListener(new View.OnClickListener() { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getBottom, getLeft, getRight, getTop
51:	return (but.getTop()<y && but.getBottom()>y && 
52:	but.getLeft()<x && but.getRight()>x); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setOnClickListener, setText
62:	mButton2 = new Button(this); 
63:	mButton2.setText("Dialog WITH EditText");//(R.string.open_dialog_nonscrollable); 
64:	mButton2.setOnClickListener(new View.OnClickListener() 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setOnClickListener, setText
59:	button = new Button(this); 
60:	button.setText("GO"); 
61:	button.setOnClickListener(this); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setOnClickListener, setText
75:	Button button = new Button(this); 
76:	button.setText("Remove/Add"); 
77:	button.setOnClickListener(new View.OnClickListener() { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setOnClickListener, setText
54:	Button button = new Button(this); 
55:	button.setText("Invalidate"); 
56:	button.setOnClickListener(new View.OnClickListener() { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setOnClickListener, setText
88:	Button btn = new Button(context); 
89:	btn.setText(buttonLabelId); 
90:	btn.setOnClickListener(new View.OnClickListener() { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setOnClickListener, setText
45:	Button result = new Button(CONTEXT); 
46:	result.setText(name); 
47:	result.setOnClickListener(new OnClickListener() { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setOnClickListener, setText
18:	Button button = new Button(this); 
19:	button.setText("Create Notification"); 
20:	button.setOnClickListener(new View.OnClickListener() { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setLayoutParams, setOnClickListener, setTag, setText
27:	Button b = new Button(this); 
-
29:	b.setLayoutParams(layoutParams); 
30:	b.setText(demoName); 
31:	b.setTag(activityClass); 
32:	b.setOnClickListener(this); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setOnClickListener, setText
54:	Button button = new Button(this); 
55:	button.setText("Invalidate"); 
56:	button.setOnClickListener(new View.OnClickListener() { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: requestFocus, setFocusableInTouchMode, setText
53:	Button button = new Button(this); 
54:	button.setText("The focus is here."); 
55:	button.setFocusableInTouchMode(true); 
56:	button.requestFocus(); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: setOnClickListener, setText
50:	mButton2 = new Button(this); 
51:	mButton2.setText("Dialog WITH EditText");//(R.string.open_dialog_nonscrollable); 
52:	mButton2.setOnClickListener(new View.OnClickListener() 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setOnClickListener, setText
49:	Button newButton = new Button(LayoutAnimationsByDefault.this); 
50:	newButton.setText(String.valueOf(numButtons++)); 
51:	newButton.setOnClickListener(new View.OnClickListener() { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setEnabled
46:	viewButton.setEnabled(true); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setMinimumHeight, setMinimumWidth, setOnClickListener, setText, setTextSize
61:	button = new Button(mContext); 
62:	button.setMinimumWidth(300); 
63:	button.setMinimumHeight(70); 
64:	button.setTextSize(14); 
65:	button.setText("Play sample"); 
66:	button.setOnClickListener(buttonListener); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setEnabled
75:	btn.setEnabled(false); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setLayoutParams, setOnClickListener, setText
65:	Button stopButton = new Button(this); 
66:	stopButton.setText("click"); 
-
72:	stopButton.setLayoutParams(buttonParams); 
-
85:	stopButton.setOnClickListener(mSnapListener); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: setEnabled
365:	_okButton.setEnabled(v); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: getLeft, getRight
78:	mLeftButton.getRight() < mCenterButton.getLeft()); 
-
80:	mCenterButton.getRight() < mRightButton.getLeft()); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setClickable, setFocusableInTouchMode, setId, setOnClickListener, setText
25:	final Button myButton = new Button(this); 
26:	myButton.setClickable(true); 
27:	myButton.setText("Keyboard UP!"); 
28:	myButton.setId(BUTTON_ID); 
29:	myButton.setFocusableInTouchMode(true); 
30:	myButton.setOnClickListener(new View.OnClickListener() 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setOnClickListener, setText
89:	Button b3 = new Button(mContext); 
90:	b3.setText("No, thanks"); 
91:	b3.setOnClickListener(new OnClickListener() { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setOnClickListener, setText
52:	mButton1 = new Button(this); 
53:	mButton1.setText("Dialog WITHOUT EditText");//(R.string.open_dialog_scrollable); 
54:	mButton1.setOnClickListener(new View.OnClickListener() 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getContext, setBackgroundDrawable, setTextColor
209:	Theme theme = ThemeUtil.createTheme(button.getContext()); 
210:	button.setTextColor(theme.getColorStateList("selector_btn_action_positive")); 
211:	button.setBackgroundDrawable(theme.getDrawable("selector_btn_action_positive")); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setEnabled
72:	btn.setEnabled(true); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setEnabled
188:	mOkButton.setEnabled(false); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setOnClickListener, setText
37:	Button result = new Button(context); 
38:	result.setText(name); 
39:	result.setOnClickListener(new View.OnClickListener() { 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setOnClickListener, setEnabled
112:	btnPositive.setEnabled(true); 
-
114:	btnPositive.setOnClickListener(positiveClickListener); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setLayoutParams, setOnClickListener, setText
34:	Button b = new Button(this); 
35:	b.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, 
-
37:	b.setText("Show dialog"); 
38:	b.setOnClickListener(new View.OnClickListener() { 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: setFocusable, setEnabled
109:	mSendButton.setEnabled(mCanSend); 
110:	mSendButton.setFocusable(mCanSend); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setEnabled
44:	viewButton.setEnabled(true); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setOnClickListener, setText
45:	Button result = new Button(CONTEXT); 
46:	result.setText(name); 
47:	result.setOnClickListener(new OnClickListener() { 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setOnClickListener, setText
61:	Button btn=new Button(this); 
-
63:	btn.setText("Randomize!"); 
64:	btn.setOnClickListener(new View.OnClickListener() { 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setOnClickListener, setText
49:	Button button = new Button(this); 
50:	button.setText("Copy bitmap to /sdcard/textureview.png"); 
51:	button.setOnClickListener(new View.OnClickListener() { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setLayoutParams, setOnClickListener, setText
141:	Button returnBtn = new Button(this); 
-
145:	returnBtn.setText("取消"); 
-
152:	returnBtn.setLayoutParams(wrapParams); 
153:	returnBtn.setOnClickListener(new View.OnClickListener() { 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setContentDescription, setEnabled
204:	mRight.setEnabled(enabled); 
-
207:	mRight.setContentDescription(null); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setOnClickListener, setText
36:	btn=new Button(this); 
-
41:	btn.setText(String.valueOf(prefs.getInt(KEY, 0))); 
42:	btn.setOnClickListener(this); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setOnClickListener, setText
49:	Button button = new Button(this); 
50:	button.setText("Copy bitmap to /sdcard/textureview.png"); 
51:	button.setOnClickListener(new View.OnClickListener() { 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setBackgroundColor, setText
72:	final Button midview = new Button(context); 
73:	midview.setText("This is a button in the FrameLayout."); 
74:	midview.setBackgroundColor(Color.GRAY); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setOnClickListener, setText
36:	btn=new Button(this); 
-
41:	btn.setText(String.valueOf(prefs.getInt(KEY, 0))); 
42:	btn.setOnClickListener(this); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setOnClickListener, setText
59:	button = new Button(this); 
60:	button.setText("GO"); 
61:	button.setOnClickListener(this); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setBackgroundResource, setOnClickListener, setTag
216:	uploadFile = new Button(layoutWidget.getContext()); 
-
218:	uploadFile.setTag("file:" + getAttributeName()); 
219:	uploadFile.setBackgroundResource(android.R.drawable.ic_menu_upload); 
220:	uploadFile.setOnClickListener(new View.OnClickListener() { 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: post
16:	quickButton.post(new Runnable() { 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setLayoutParams, setText
32:	Button b = new Button(this); 
33:	b.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, 
-
35:	b.setText("9 patches"); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setBackgroundResource, setOnClickListener
106:	btn = new Button(ctx); 
107:	btn.setBackgroundResource(android.R.drawable.ic_menu_agenda); 
-
109:	btn.setOnClickListener(this); 
Full Snippet Info
6
CodeRank
Related Android Button Questions & Answers:
Other Android Button Examples
14:	  private ObjectAnimator animation1;
15:	  private ObjectAnimator animation2;
16:	  private Button button;
17:	  private Random randon;
18:	  private int width;
-
57:	    int nextX = randon.nextInt(width);
58:	    int nextY = randon.nextInt(height);
59:	    button = (Button) findViewById(R.id.button1);
60:	    animation1 = ObjectAnimator.ofFloat(button, "x", nextX);
61:	    animation1.setDuration(1400);

Read More

2:	// Creating a button - Load More
3:	Button btnLoadMore = new Button(this);
4:	btnLoadMore.setText("Load More");
5:	
6:	// Adding button to listview at footer
-
2:	// Creating a button - Load More
3:	Button btnLoadMore = new Button(this);
4:	btnLoadMore.setText("Load More");
5:	
6:	// Adding button to listview at footer

Read More

18:	         * */
19:	        // Dashboard News feed button
20:	        Button btn_newsfeed = (Button) findViewById(R.id.btn_news_feed);
21:	        
22:	        // Dashboard Friends button
-
18:	         * */
19:	        // Dashboard News feed button
20:	        Button btn_newsfeed = (Button) findViewById(R.id.btn_news_feed);
21:	        
22:	        // Dashboard Friends button
-
21:	        
22:	        // Dashboard Friends button
23:	        Button btn_friends = (Button) findViewById(R.id.btn_friends);
24:	        
25:	        // Dashboard Messages button
-
21:	        
22:	        // Dashboard Friends button
23:	        Button btn_friends = (Button) findViewById(R.id.btn_friends);
24:	        
25:	        // Dashboard Messages button
-
24:	        
25:	        // Dashboard Messages button
26:	        Button btn_messages = (Button) findViewById(R.id.btn_messages);
27:	        
28:	        // Dashboard Places button
-
24:	        
25:	        // Dashboard Messages button
26:	        Button btn_messages = (Button) findViewById(R.id.btn_messages);
27:	        
28:	        // Dashboard Places button
-
27:	        
28:	        // Dashboard Places button
29:	        Button btn_places = (Button) findViewById(R.id.btn_places);
30:	        
31:	        // Dashboard Events button
-
27:	        
28:	        // Dashboard Places button
29:	        Button btn_places = (Button) findViewById(R.id.btn_places);
30:	        
31:	        // Dashboard Events button
-
30:	        
31:	        // Dashboard Events button
32:	        Button btn_events = (Button) findViewById(R.id.btn_events);
33:	        
34:	        // Dashboard Photos button
-
30:	        
31:	        // Dashboard Events button
32:	        Button btn_events = (Button) findViewById(R.id.btn_events);
33:	        
34:	        // Dashboard Photos button
-
33:	        
34:	        // Dashboard Photos button
35:	        Button btn_photos = (Button) findViewById(R.id.btn_photos);
36:	        
37:	        /**
-
33:	        
34:	        // Dashboard Photos button
35:	        Button btn_photos = (Button) findViewById(R.id.btn_photos);
36:	        
37:	        /**

Read More

8:	public class MainScreenActivity extends Activity{
9:	
10:		Button btnViewProducts;
11:		Button btnNewProduct;
12:	
-
9:	
10:		Button btnViewProducts;
11:		Button btnNewProduct;
12:	
13:		@Override
-
17:	
18:			// Buttons
19:			btnViewProducts = (Button) findViewById(R.id.btnViewProducts);
20:			btnNewProduct = (Button) findViewById(R.id.btnCreateProduct);
21:	
-
18:			// Buttons
19:			btnViewProducts = (Button) findViewById(R.id.btnViewProducts);
20:			btnNewProduct = (Button) findViewById(R.id.btnCreateProduct);
21:	
22:			// view products click event

Read More

1:	Button myButton = (Button) findViewById(R.id.my_button);
2:	
-
1:	Button myButton = (Button) findViewById(R.id.my_button);
2:

Read More

1:	Button button = (Button) findViewById(R.id.button_send);
2:	button.setOnClickListener(new View.OnClickListener() {
3:	    public void onClick(View v) {
-
1:	Button button = (Button) findViewById(R.id.button_send);
2:	button.setOnClickListener(new View.OnClickListener() {
3:	    public void onClick(View v) {

Read More

2:	public void testNextActivityWasLaunchedWithIntent() {
3:	    startActivity(mLaunchIntent, null, null);
4:	    final Button launchNextButton =
5:	            (Button) getActivity()
6:	            .findViewById(R.id.launch_next_activity_button);
-
3:	    startActivity(mLaunchIntent, null, null);
4:	    final Button launchNextButton =
5:	            (Button) getActivity()
6:	            .findViewById(R.id.launch_next_activity_button);
7:	    launchNextButton.performClick();

Read More

See Code Examples for Android Button Methods: