Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

onclick android

//declare and define the button
Button button = (Button) findViewById(R.id.button1);




//method 1: set the onclick eventlistener with java only
button.setOnClickListener(new OnClickListener() {
  public void onClick(View v) {
    // TODO Auto-generated method stub
  }
 });
/////




//method 2:use also layout code (xml)

//xml:
//add the following :
android:onClick="functionName"
//to the view you want to add the eventlistener to 
  
//java: add to the main class
  public void functionName(View v) {

}
  
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #onclick #android
ADD COMMENT
Topic
Name
3+5 =