Android Button - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Button class.

This code example shows how to use the following methods: setOnClickListener, setTag, setText
                                             LayoutParams.FILL_PARENT,
                                             1.0f); 
    } 
 
    public void addButton(String aText, int aCallback) {
        Button mButton = new Button(mContext);
        mButton.setText(aText);
        mButton.setTag(Integer.toString(aCallback));
        mButton.setOnClickListener(this);
        mChoicesLayout.addView(mButton, mLayoutParams);
    } 
 
    public void onClick(View v) {
        GeckoEvent e = GeckoEvent.createBroadcastEvent("Doorhanger:Reply", v.getTag().toString());
        GeckoAppShell.sendEventToGecko(e);
        mTab.removeDoorHanger(mValue);
 
        // This will hide the doorhanger (and hide the popup if there are no 
        // more doorhangers to show) 
        GeckoApp.mDoorHangerPopup.updatePopup(); 
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: getContext, setCompoundDrawablePadding, setCompoundDrawablesWithIntrinsicBounds, setPadding, setText
 
        return false; 
    } 
 
    public static void applyButtonDef(@Nonnull Button button, @Nonnull ButtonDef buttonDef) {
        button.setText(buttonDef.getText());
 
        final Integer drawableResId = buttonDef.getDrawableResId();
        if ( drawableResId != null ) {
            button.setPadding(0, 0, 0, 0);
 
            final Drawable drawable = button.getContext().getResources().getDrawable(drawableResId);
            button.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null);
            button.setCompoundDrawablePadding(0);
        } 
 
        applyViewDef(button, buttonDef);
    } 
 
    public static void applyButtonDef(@Nonnull ImageButton imageButton, @Nonnull ButtonDef buttonDef) {
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: setOnClickListener, setText
    public static final int[] HORIZONTAL_ALIGNMENTS = { LEFT, CENTER, RIGHT, FILL };
    public static final String[] VERTICAL_NAMES = { "TOP", "CENTER", "BASELINE", "BOTTOM", "FILL" };
    public static final int[] VERTICAL_ALIGNMENTS = { TOP, CENTER, NO_GRAVITY, BOTTOM, FILL };
 
    public View create(Context context, String name, int size) {
        Button result = new Button(context);
        result.setText(name);
        result.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                animate(v);
            } 
        }); 
        return result;
    } 
 
    public abstract ViewGroup create(Context context);
    public abstract String tag();
 
    public void animate(View v) {
        long start = System.currentTimeMillis();
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: getBottom, getLeft, getRight, getTop
		} 
		return true; 
	} 
     
    private boolean isInside(Button but, float x, float y) {
    	return (but.getTop()<y && but.getBottom()>y &&
    		but.getLeft()<x && but.getRight()>x);
    } 
} 
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: setOnClickListener, setText
showDialog(DIALOG_WITHOUT_EDITTEXT);
            } 
        }); 
 
        mButton2 = new Button(this);
        mButton2.setText("Dialog WITH EditText");//(R.string.open_dialog_nonscrollable);
        mButton2.setOnClickListener(new View.OnClickListener() 
        { 
            public void onClick(View v) 
            { 
                showDialog(DIALOG_WITH_EDITTEXT);
            } 
        }); 
 
        mEditText = new EditText(this);
        mLayout.addView(mEditText);
        mLayout.addView(mButton1);
        mLayout.addView(mButton2);
 
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: setOnClickListener, setText
 
        Thread requestThread = new Thread(this);
        requestThread.setDaemon(true);
        requestThread.start();
 
        button = new Button(this);
        button.setText("GO");
        button.setOnClickListener(this);
 
        setContentView(button);
    } 
     
    @Override 
    protected void onStop() { 
        super.onStop(); 
 
        synchronized (this) {
            running = false;
        } 
    } 
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: setOnClickListener, setText
                    } 
                } 
            } 
        }); 
 
        Button button = new Button(this);
        button.setText("Remove/Add");
        button.setOnClickListener(new View.OnClickListener() {
            private boolean mAdded = true;
 
            @Override 
            public void onClick(View v) {
                if (mAdded) {
                    mContent.removeView(mTextureView);
                } else { 
                    mContent.addView(mTextureView);
                } 
                mAdded = !mAdded;
            } 
        }); 
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: setOnClickListener, setText
 
        setContentView(root);
    } 
 
    private Button createButton(final LinearLayout root) {
        Button button = new Button(this);
        button.setText("Invalidate");
        button.setOnClickListener(new View.OnClickListener() {
            @Override 
            public void onClick(View v) {
                for (int i = 0; i < root.getChildCount(); i++) {
                    View child = root.getChildAt(i);
                    if (child != v) {
                        child.invalidate();
                    } 
                } 
            } 
        }); 
 
        return button;
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: setOnClickListener, setText
        layout.addView(buttonHolder, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.FILL_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
 
        // Add the OK button. 
        Button btn = new Button(context);
        btn.setText(buttonLabelId);
        btn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                dismiss();
            } 
        }); 
        buttonHolder.addView(btn, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT, 1));
 
        return layout;
    } 
} 
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: setOnClickListener, setText
        View create(String name, int size);
    } 
 
    public static final ViewFactory BUTTON_FACTORY = new ViewFactory() {
        public View create(String name, int size) { 
            Button result = new Button(CONTEXT); 
            result.setText(name); 
           result.setOnClickListener(new OnClickListener() { 
               @Override 
               public void onClick(View v) { 
                    animate(v); 
               } 
           }); 
            return result; 
        } 
    }; 
 
    public static final ViewFactory LABEL_FACTORY = new ViewFactory() {
        public View create(String name, int size) { 
            TextView result = new TextView(CONTEXT); 
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

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: