Mick
0
Q:

android studio button usage

//this for xml file 
<Button  
        android:id="@+id/button"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_centerHorizontal="true"  
        android:layout_marginTop="109dp"  
        android:text="hello"  
 /> 

//this for java file 
Button btn;
  @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.activity_main);  
  btn = (Button) findViewById(R.id.button);
        btn.setOnClickListener(new View.OnClickListener() {  
            @Override  
            public void onClick(View view) {  
               //do something
            }  
        }); 
    } 
1
Button b = findById();
1
mycodes_Button.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        mycodes_Button.setPressed(true);
        return true;
    }
});
-1

New to Communities?

Join the community