tags:

views:

47

answers:

2

I am new to android. I want to set OnclickListner for different buttons which are located in different xml layouts.

+1  A: 

Something like this:

  final Button button = (Button) findViewById(R.id.button_id);
             button.setOnClickListener(new View.OnClickListener() {
                 public void onClick(View v) {
                     // Perform action on click
                 }
             });

Then all you need to do is reference the different buttons by their different ids set in the XML

BeRecursive
hi..we can do it by what BeRecursive given..
MGSenthil
thanks for the answers.
mohammedsuhail
+3  A: 

You can also use a definition like that directly in the XML-file:

<Button android:onClick="myClickHandler" />

After that you can create the method "myClickHandler" in your Code like that:

class MyActivity extends Activity {
    public void myClickHandler(View target) {
        // Do stuff
    }
}
chromate