You can write this way also public class testActivity extends Activity implements OnClickListener { And Add this way ImageButton Ibutton = (ImageButton) findViewById(R.id. Button_1); Ibutton. SetOnClickListener(this); ImageButton Ibutton2 = (ImageButton) findViewById(R.id.
Button_2); Ibutton2. SetOnClickListener(this); @Override public void onClick(View v) { switch(v.getId()){ case R.id. Button_1: // action to preform on button 1 Toast.
MakeText(testActivity. This, "Button 1 pressed ", Toast. LENGTH_SHORT).show(); break; case R.id.
Button_2: // action to preform on button 1 Toast. MakeText(testActivity. This, "Button 2 pressed ", Toast.
LENGTH_SHORT).show(); break; } }.
You can write this way also public class testActivity extends Activity implements OnClickListener { And Add this way... ImageButton Ibutton = (ImageButton) findViewById(R.id. Button_1); Ibutton. SetOnClickListener(this); ImageButton Ibutton2 = (ImageButton) findViewById(R.id.
Button_2); Ibutton2. SetOnClickListener(this); @Override public void onClick(View v) { switch(v.getId()){ case R.id. Button_1: // action to preform on button 1 Toast.
MakeText(testActivity. This, "Button 1 pressed ", Toast. LENGTH_SHORT).show(); break; case R.id.
Button_2: // action to preform on button 1 Toast. MakeText(testActivity. This, "Button 2 pressed ", Toast.
LENGTH_SHORT).show(); break; } }.
Ok that works for me. Just courious - do you understand the piece of code i've quoted? It's not clear to mee – yotamoo Jun 15 at 14:12.
As each view is attached with separate listener you each event can recognize that it belongs to which view use the following approach step1 your class should implement OnclickListener eg public class A implements OnClickListener step2 Add onclicklistener to all buttons button1 = (Button) findViewById(R.id. Btn1); button2 = (Button) findViewById(R.id. Btn2); button3 = (Button) findViewById(R.id.
Btn3); button1. SetOnClickListener(this); button2. SetOnClickListener(this); button3.
SetOnClickListener(this); step3 write implementation of onClickMethod @Override public void onClick(View view) { if (view == button1) { //do button1 click action } else if (view ==button2) { //do button2 click action } else if (view == button3) { //do button3 click action }.
This is a really good answer! – diagonalbatman Jun 15 at 14:04 @diagonalbatman thanks – Sunil Kumar Sahoo Jun 15 at 14:16.
Had the chance of writing a gui so I don't know much about listeners. Its a method? Two more question: if I have several buttons on the screen, they all share the same onCLick() method?
And if so, how do I know which one was clicked?
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.