How To Compare Data(int) In The First And Data(int) In Second Button In Android?
I have a problem where I want to make the comparison the data in button package lynn.calculate.KaunterKalori; import lynn.calculate.KaunterKalori.R; import android.app.Activity; i
Solution 1:
It's a scoping problem, you are declaring int TotalKalori locally in the onClick event.
Declare it like you have done with totalKalori1 and it should work
Solution 2:
Or you can use getTag(); setTag(); to store the variables on the buttons...
Use setTag to the data you want
myButton.setTag("fun Stuff");
Then on the listener just get the tag (you will need to do a type cast):
OnClickListener myListner = newOnClickListener() {
publicvoidonClick(View view) {
doSomethingAwesome(view, (String) view.getTag());
}
};
Solution 3:
Declare int TotalKalori only once globally (in the section you declared protected int totalKalori1; protected int totalKalori2;...
) and simply use it for both buttons like: in button1 TotalKalori = calculateTotalKalori(totalKalori1, totalKalori2,totalKalori3); this value is global so button2 already can acess it by simply using TotalKalori where you need and also the comparison portion.
Post a Comment for "How To Compare Data(int) In The First And Data(int) In Second Button In Android?"