• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Button + Button = TextView

I'm a noob with Java but have a question that I cant seem to find the answer too.

How do I have multiple buttons, each with different numerical values that when clicked add to each other and results shown in the TextView without requiring the click of an equals button. I was going to try to copy the theory of the onclick from this calculator code but it didn't work because I either did it wrong or I am just too stupid! http://mrbool.com/how-to-create-a-calculator-app-for-android/28100

For example:

Button 1 (2.40) + Button 2 (1.00) + Button 3 (3.20) = TextView (6.60)

or

Button 1 (2.40) + Button 2 (1.00) + Button 2 (1.00) + Button 3 (3.20) = TextView (7.60)

Etc, etc.

If anyone could help I would really appreciate it.
 
you could update the textview in each button's onClickListener
eg:

button1.setOnClickListener(new OnClickListener()
{
public void onClick(View v){

total += button1_value;

textview_total.setText(Integer.toString(total));
}
};
 
Last edited:
Back
Top Bottom