i have to check simentaneously one one radiobutton and see the value of timeone if ab1 is clicked through toast.. , how can i see it .. i am using is "rab"+number of radiobutton.ischecked() method. is it ok or anyother method should be used ?
public class Alarmsettings extends Activity {
RadioButton rab1,rab2,rab3,rab0;
RadioGroup rg;
Button ab1,ab2;
public Integer timeone;
public Alarmsettings()
{
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_layout);
rab0=(RadioButton) findViewById(R.id.radio0);
rab1=(RadioButton) findViewById(R.id.radio1);
rab2=(RadioButton) findViewById(R.id.radio2);
rab3=(RadioButton) findViewById(R.id.radio3);
ab1=(Button) findViewById(R.id.button1);
ab2=(Button) findViewById(R.id.button2);
rg = (RadioGroup) findViewById(R.id.radioGroup1);
if(rab0.isChecked())
timeone=15;
else if(rab1.isChecked())
timeone=30;
else if(rab2.isSelected())
timeone=45;
else if(rab3.isChecked())
timeone=60;
ab1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),timeone.toString(), Toast.LENGTH_SHORT).show();
Try assigning the values through flags rather than assigning it directly
if(rab0.isChecked())
flag=1;
else if(rab1.isChecked())
flag=2;
else if(rab2.isSelected())
flag=3;
else if(rab3.isChecked())
flag=4;
ab1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if(flag == 1)
timeone=15;
else if(flag == 2)
timeone=30;
else if(flag == 3)
timeone=45;
else if(flag == 4)
timeone=60;
Toast.makeText(getApplicationContext(),timeone.toString(), Toast.LENGTH_SHORT).show();
Hope this helps.
Related
i am trying to make a program which compares a string
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
InputMethodManager imm=(InputMethodManager)getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
if(inpt==null)op.setText("Please Enter");
else if (inpt.equals("a")) op.setText("a entered");
else if (inpt.equals("b")) op.setText("b entered");
else op.setText("unknown keyword");
but the else statement is always executed. Please help me correct this code
i am a beginner and don't know much yet.......
Its because this inpt string is declared final. Means value can not be change and string inpt have to update every time when onClick action is performed. Otherwise it will take the same value and gets excuted the else part. So i removed the final keyword and declared the string inside the onClick function. Try this.
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText ip=(EditText)findViewById(R.id.ip);
final TextView op=(TextView)findViewById(R.id.op);
//final String inpt=ip.getText().toString();
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String inpt=ip.getText().toString();
InputMethodManager imm=(InputMethodManager)getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
if(inpt==null)op.setText("Please Enter");
else if (inpt.equals("a")) op.setText("a entered");
else if (inpt.equals("b")) op.setText("b entered");
else op.setText("Unknown keyword");
}
});
}
I created this android app using the MPAndroidChart Library, which allows the user to create a quick PieChart using an ArrayList (I added some screenshots, for clarification).
My problem is that I want to allow the user to delete an entry from the piechart (and the array list), the pie chart should then be rendered without the removed entry.
Is there any way I can achieve this by allowing the user to long press an item, which opens some sort of yes/no dialog?
Screenshots gallery
Code:
package com.example.quickpie;
public class Main extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final List<PieEntry> entries = new ArrayList<>();
final EditText editText = (EditText) findViewById(R.id.editText);
final EditText editText2 = (EditText) findViewById(R.id.editText2);
final EditText editText3 = (EditText) findViewById(R.id.editText3);
final Button button = (Button) findViewById(R.id.button);
final Button button2 = (Button) findViewById(R.id.button2);
final TextView textView = (TextView) findViewById(R.id.textView);
final TextView textView2 = (TextView) findViewById(R.id.textView2);
final TextView textView3 = (TextView) findViewById(R.id.textView3);
editText.requestFocus();
button.setOnClickListener(new View.OnClickListener() {
public void onClick (View v) {
//if(editText.getFreezesText())
if (editText.getText().toString().matches("")) {
Toast.makeText(getBaseContext(), "You did not enter a Valid Item ID", Toast.LENGTH_LONG).show();
return;
}
else if (editText2.getText().toString().matches("")) {
Toast.makeText(getBaseContext(), "You did not enter a Valid Quantitiy", Toast.LENGTH_LONG).show();
return;
}
else {
String nomen = (editText.getText().toString());
float number = Float.parseFloat(editText2.getText().toString());
final PieChart piechart = (PieChart) findViewById(R.id.piechart);
entries.add(new PieEntry(number, nomen));
editText.setText("");
editText2.setText("");
textView3.setSingleLine(false);
textView3.append("\n" + nomen + " " + number);
editText.requestFocus();
PieDataSet set = new PieDataSet(entries, "");
//colors
getResources().getColor(R.color.violp);
getResources().getColor(R.color.bluep);
getResources().getColor(R.color.redp);
getResources().getColor(R.color.greenp);
getResources().getColor(R.color.yellowp);
getResources().getColor(R.color.orangep);
getResources().getColor(R.color.lightbluep);
getResources().getColor(R.color.purplep);
getResources().getColor(R.color.darkredp);
set.setColors(new int[]{R.color.bluep, R.color.greenp, R.color.violp, R.color.redp, R.color.yellowp, R.color.orangep, R.color.lightbluep, R.color.purplep, R.color.darkredp}, getApplicationContext());
PieData data = new PieData(set);
piechart.setData(data);
Description description = new Description();
description.setText(getResources().getString(R.string.besch));
piechart.setDescription(description);
Toast.makeText(getBaseContext(), (R.string.loading),
Toast.LENGTH_SHORT).show();
String mitte = (editText3.getText().toString());
piechart.setCenterText(mitte);
piechart.setCenterTextSize(30);
piechart.setNoDataText(String.valueOf(R.string.nodata));
piechart.notifyDataSetChanged();
piechart.animateX(2000, Easing.EasingOption.EaseInExpo);
piechart.animateY(2000, Easing.EasingOption.EaseInExpo);
piechart.invalidate();
editText3.setVisibility(View.VISIBLE);
editText3.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
String mitte = (editText3.getText().toString());
piechart.setCenterText(mitte);
editText3.setText("");
editText.requestFocus(); //editText3.setVisibility(View.INVISIBLE);
InputMethodManager imm = (InputMethodManager) getSystemService(Main.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
//do something
}
return false;
}
});
editText3.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEvent.ACTION_UP == event.getAction()) {
piechart.setCenterText("");
textView3.setHint(R.string.hint1);
}
return false; // return is important...
}
});
button.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
Toast.makeText(getBaseContext(), R.string.longpresshint, Toast.LENGTH_LONG).show();
return true;
}
});
final Button button2 = (Button) findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String mitte = (editText3.getText().toString());
piechart.setCenterText(mitte);
//piechart.setVisibility(View.VISIBLE);
//editText.setVisibility(View.INVISIBLE);
//textView2.setVisibility(View.INVISIBLE);
//textView3.setVisibility(View.INVISIBLE);
//editText3.setVisibility(View.INVISIBLE);
// editText2.setVisibility(View.INVISIBLE);
//button.setVisibility(View.INVISIBLE);
//button2.setVisibility(View.INVISIBLE);
Toast.makeText(getBaseContext(), (R.string.loading),
Toast.LENGTH_SHORT).show();
piechart.animateX(2000, Easing.EasingOption.EaseInExpo);
piechart.animateY(2000, Easing.EasingOption.EaseInExpo);
InputMethodManager imm = (InputMethodManager) getSystemService(Main.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
}
});
}}
}
)
;
}
#Override
public void onBackPressed(){
super.onBackPressed();
Intent intent = getIntent();
finish();
startActivity(intent);
}
}
Please try this
button.setOnClickListener(new View.OnClickListener() {
public void onClick (View v) {
//if(editText.getFreezesText())
if (editText.getText().toString().matches("")) {
Toast.makeText(getBaseContext(), "You did not enter a Valid Item ID", Toast.LENGTH_LONG).show();
return;
}
else if (editText2.getText().toString().matches("")) {
Toast.makeText(getBaseContext(), "You did not enter a Valid Quantitiy", Toast.LENGTH_LONG).show();
return;
}
else {
piechart.invalidate();
}
This is my coding. I don't know how to validate the radio button. When I click the next button,it still can proceed eventhough the radio button is not clicked. Sorry for my bad English.Please help me. Thank you.
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dengue_ques2);
radioGroup = (RadioGroup) findViewById(R.id.radioGroupDengue2);
yes2 = (RadioButton) findViewById(R.id.radioButtonQues2); //the answer is yes
no2 = (RadioButton) findViewById(R.id.radioButtonQues2No); //the answer is no
Next=(Button) findViewById(R.id.buttonNextQues2);
yes2.setSelected(true);
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
if (i == R.id.radioButtonQues2)
{
selectedType = yes2.getText().toString();
}
else if (i == R.id.radioButtonQues2No)
{
selectedType = no2.getText().toString();
}
/* this part does not work
else if (i == R.id.radioButtonQues2.isChecked(false) &&
i == R.id.radioButtonQues2No.isChecked(false))
{
Toast.makeText(this, "Please choose 1 answer",
Toast.LENGTH_SHORT).show();
}*/
}
});
Next.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(dengueQues2.this, dengueQues3.class);
intent.putExtra("REST2", selectedType);
startActivity(intent);
}
});
}
public void onClickYes2 (View view)
{
Toast.makeText(this, "You have select 1 to 3 days.",Toast.LENGTH_SHORT).show();
}
public void onClickNo2 (View view)
{
Toast.makeText(this, "You have select 3 to 14 days.", Toast.LENGTH_SHORT).show();
}
You need to use the setChecked() method not the setSelected() method on the radio button.
Also you need to default selectedType = yes2.getText().toString(); since you are setting that as the default selection in onCreate().
yes2.setChecked(true);
selectedType = yes2.getText().toString();
EDIT showing how to use no default selection:
Next.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(yes2.isChecked() || no2.isChecked()) {
Intent intent = new Intent(dengueQues2.this, dengueQues3.class);
intent.putExtra("REST2", selectedType);
startActivity(intent);
} else {
Toast.makeText(this, "Please choose 1 answer",
Toast.LENGTH_SHORT).show();
}
}
});
I have a radio button activity with 5 choices for the game. It's a quiz game, so the user can choose to play until he or she makes one error, two errors, tree, four and five errors. My question is....is it better to make 5 activities and 5 classes, so I can call intent of each activity when user check that radio button, or, is better to make one activity, for all five choices and depending on what user chose, to count until 1,2,3,4 or 5 errors? I know how do the first option, but I don't know how to do the second one. Here my choice activity:
public class Izbor extends Activity implements OnClickListener, OnCheckedChangeListener{
MediaPlayer buttonBack;
RadioButton rbDeset,rbDvadeset,rbNeogranicenoTriGreske,rbNeogranicenoJednaGreska,rbNeogranicenoPetGresaka;
Button dNazad, dStart;
RadioGroup rGrupa;
TextView tv1;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.izbor);
addListenerOnButton();
}
private void addListenerOnButton() {
Typeface dugmad = Typeface.createFromAsset(getAssets(), "Bebas.ttf");
Typeface pitanjeVrh = Typeface.createFromAsset(getAssets(), "Lobster.ttf");
rbDeset = (RadioButton) findViewById(R.id.radio1);
rbDvadeset = (RadioButton) findViewById(R.id.radio2);
rbNeogranicenoJednaGreska = (RadioButton) findViewById(R.id.radio3);
rbNeogranicenoTriGreske = (RadioButton) findViewById(R.id.radio4);
rbNeogranicenoPetGresaka = (RadioButton) findViewById(R.id.radio5);
dNazad = (Button) findViewById(R.id.bNazad);
dStart = (Button) findViewById(R.id.bStart);
rGrupa = (RadioGroup) findViewById(R.id.radioGroup1);
buttonBack = MediaPlayer.create(Izbor.this, R.raw.back);
tv1 = (TextView) findViewById(R.id.tv1);
dNazad.setTypeface(dugmad);
dStart.setTypeface(dugmad);
rbDeset.setTypeface(dugmad);
rbDvadeset.setTypeface(dugmad);
rbNeogranicenoPetGresaka.setTypeface(dugmad);
rbNeogranicenoJednaGreska.setTypeface(dugmad);
rbNeogranicenoTriGreske.setTypeface(dugmad);
tv1.setTypeface(pitanjeVrh);
rGrupa.setOnCheckedChangeListener(this);
rbDeset.setOnClickListener(this);
rbDvadeset.setOnClickListener(this);
rbNeogranicenoJednaGreska.setOnClickListener(this);
rbNeogranicenoTriGreske.setOnClickListener(this);
rbNeogranicenoPetGresaka.setOnClickListener(this);
dStart.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(rbDeset.isChecked()){
startActivity(new Intent("rs.androidaplikacijekvizopstekulture.KVIZ"));
}else if(rbDvadeset.isChecked()){
startActivity(new Intent("rs.androidaplikacijekvizopstekulture.DVADESETPITANJA"));
}else if(rbNeogranicenoJednaGreska.isChecked()){
startActivity(new Intent("rs.androidaplikacijekvizopstekulture.TRIDESETPITANJA"));
}else if(rbNeogranicenoPetGresaka.isChecked()){
startActivity(new Intent("rs.androidaplikacijekvizopstekulture.NEOGRANICENOPETGRESAKA"));
}
}
});
dNazad.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
buttonBack.start();
finish();
}
});
}
public void onCheckedChanged(RadioGroup group, int checkedId) {
}
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
And here is one activity where a user can play until 5 mistakes:
public class NeogranicenoPetGresaka extends Activity implements OnClickListener{
Button bIzlazIzKviza, bOdgovor1, bOdgovor2, bOdgovor3, bOdgovor4;
TextView question, netacniOdg, score;
int counter = 0;
int brojacPogresnihOdgovora = 0;
int brojacTacnihOdgovora = 0;
Runnable mLaunchTask = new Runnable() {
public void run() {
nextQuestion();
}
};
Runnable mLaunchTaskFinish = new Runnable() {
public void run() {
finish();
}
};
private class Answer {
public Answer(String opt, boolean correct) {
option = opt;
isCorrect = correct;
}
String option;
boolean isCorrect;
}
Handler mHandler = new Handler();
final OnClickListener clickListener = new OnClickListener() {
public void onClick(View v) {
Answer ans = (Answer) v.getTag();
if (ans.isCorrect) {
brojacTacnihOdgovora++;
Intent i = new Intent("rs.androidaplikacijekvizopstekulture.TACANODGOVOR");
startActivity(i);
mHandler.postDelayed(mLaunchTask,1200);
}
else{
brojacPogresnihOdgovora++;
Intent i = new Intent("rs.androidaplikacijekvizopstekulture.POGRESANODGOVOR");
startActivity(i);
mHandler.postDelayed(mLaunchTask,2200);
}
}
};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.neograniceno5gresaka);
Typeface dugmad = Typeface.createFromAsset(getAssets(), "Bebas.ttf");
Typeface pitanje = Typeface.createFromAsset(getAssets(), "Lobster.ttf");
bIzlazIzKviza = (Button) findViewById(R.id.bIzlazIzKvizaN);
netacniOdg = (TextView) findViewById(R.id.tvBrojPitanjaN);
question = (TextView) findViewById(R.id.tvPitanjeN);
bOdgovor1 = (Button) findViewById(R.id.bOdgovorN1);
bOdgovor2 = (Button) findViewById(R.id.bOdgovorN2);
bOdgovor3 = (Button) findViewById(R.id.bOdgovorN3);
bOdgovor4 = (Button) findViewById(R.id.bOdgovorN4);
score = (TextView) findViewById(R.id.tvSkor2N);
bOdgovor1.setTypeface(dugmad);
bOdgovor2.setTypeface(dugmad);
bOdgovor3.setTypeface(dugmad);
bOdgovor4.setTypeface(dugmad);
bIzlazIzKviza.setTypeface(dugmad);
netacniOdg.setTypeface(dugmad);
question.setTypeface(pitanje);
score.setTypeface(dugmad);
nextQuestion(); //startuje prvo pitanje!
}
public void onClick(View v) {
// TODO Auto-generated method stub
}
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
public void nextQuestion() {
TestAdapter mDbHelper = new TestAdapter(this);
mDbHelper.createDatabase();
try{ //Pokusava da otvori db
mDbHelper.open(); //baza otvorena
Cursor c = mDbHelper.getTestData();
List<Answer> labels = new ArrayList<Answer>();
labels.add(new Answer(c.getString(2), true));
labels.add(new Answer(c.getString(3), false));
labels.add(new Answer(c.getString(4), false));
labels.add(new Answer(c.getString(5), false));
Collections.shuffle(labels);
if(brojacPogresnihOdgovora < 5){
question.setText(c.getString(1));
bOdgovor1.setText(labels.get(0).option);
bOdgovor1.setTag(labels.get(0));
bOdgovor1.setOnClickListener(clickListener);
bOdgovor2.setText(labels.get(1).option);
bOdgovor2.setTag(labels.get(1));
bOdgovor2.setOnClickListener(clickListener);
bOdgovor3.setText(labels.get(2).option);
bOdgovor3.setTag(labels.get(2));
bOdgovor3.setOnClickListener(clickListener);
bOdgovor4.setText(labels.get(3).option);
bOdgovor4.setTag(labels.get(3));
bOdgovor4.setOnClickListener(clickListener);
//reset your next question and all four options here
netacniOdg.setText("" + brojacPogresnihOdgovora);
score.setText("Score: " + brojacTacnihOdgovora);
}
else{
Intent i = new Intent("rs.androidaplikacijekvizopstekulture.REZULTAT");
startActivity(i);
mHandler.postDelayed(mLaunchTaskFinish,4000);
}
}
finally{ // kada zavrsi sa koriscenjem baze podataka, zatvara db
mDbHelper.close();
}
bIzlazIzKviza.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();
}
});
}
}
Considering that the choice is just a small setting to the same game I see absolutely no reason to create one class/activity for each choice, it would be sheer madness.
As for the settings part, just create a numeric only input field that accepts any amount of "errors" ( why not ? ).
OnClick get the input from this field, save the value to the intent extras and start the game with the intent. In the onCreate of the game read the intent extras and get the number of "tries"/"errors".
OK, I tried with onNewIntent, but I can only call one method, and I need at least 3. Here's the code in my choice activity with radio buttons(group):
public void onClick(View v) {
if(rbDeset.isChecked()){
Intent intent = new Intent(Izbor.this, Kviz.class);
intent.putExtra("myMethod", "nextQuestion");
startActivity(intent);
And here's my quiz activity:
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if(intent.getStringExtra("methodName").equals("nextQuestion")){
nextQuestion();
}
}
I tried with ELSE IF but it didn't work. My methods are named: nextQuestion(), nextQuestion2() and nextQuestion3(). These are pretty much same methods only with different counters (one for 10 questions, one for 20 and one for 30). Maybe I don't need 3 methods to do this but honestly I don't know other way to do that.
In android app coded for common method for all buttons click event, here is the code,
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.filter);
btnOne = (Button)findViewById(R.id.btnone);
btnTwo = (Button)findViewById(R.id.btntwo);
btnThree = (Button)findViewById(R.id.btnthree);
btnFour = (Button)findViewById(R.id.btnfour);
btnFive = (Button)findViewById(R.id.btnfive);
btnSix = (Button)findViewById(R.id.btnsix);
btnSeven = (Button)findViewById(R.id.btnseven);
btnEight = (Button)findViewById(R.id.btneight);
btnNine = (Button)findViewById(R.id.btnnine);
btnTen = (Button)findViewById(R.id.btnten);
OnClickListener listener = new OnClickListener()
{
public void onClick(View v) {
// TODO Auto-generated method stub
doAction(v);
}
};
}
public void doAction(View v)
{
Object tagObject = v.getTag();
int tag = (Integer) v.getTag();
String val = (String) d.get(tag);
if(val.equals("off"))
{
//select(tagObject);
//d.put(tag, "on");
Toast.makeText(getBaseContext(), "Button"+tag+"select", Toast.LENGTH_LONG).show();
}
else if(val.equals("on"))
{
//unSelect(tagObject);
//d.put(tag, "off");
Toast.makeText(getBaseContext(), "Button"+tag+"unselect", Toast.LENGTH_LONG).show();
}
}
This code is not working for me. Please give any idea....... Thanks in advance
How about declaring your listener first and then calling setOnClickListener on your views :
OnClickListener listener = new OnClickListener()
{
public void onClick(View v) {
// TODO Auto-generated method stub
doAction(v);
}
};
btnOne.setOnClickListener(listener);
btnTwo.setOnClickListener(listener);
...
You have declared the listener but you forgot to set the listener for each button.
Do this for all buttons : btnOne.setOnClickListener(listener);
You need to set the listener in the button..
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.filter);
...
OnClickListener listener = new OnClickListener()
{
public void onClick(View v) {
// TODO Auto-generated method stub
doAction(v);
}
};
btnOne.setOnClickListener();
btnTwo = (Button)findViewById(R.id.btntwo);
...
}
Have your class implement View.OnClickListener, like
public class MyActivity extends Activity implements View.OnClickListener {
Button button1, button2, button3;
#Override
public void onCreate(Bundle bundle) {
super.onCreate();
...
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button3 = (Button) findViewById(R.id.button3);
button1.setOnClickListener(this);
button2.setOnClickListener(this);
button3.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.button1:
// do stuff;
break;
case R.id.button2:
// do stuff;
break;
...
}
}