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
2010-09-06 08:06:33
hi..we can do it by what BeRecursive given..
MGSenthil
2010-09-06 08:46:27
thanks for the answers.
mohammedsuhail
2010-09-06 12:12:30
+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
2010-09-06 08:11:27