jpgerb
jpgerb

Reputation: 1120

Allow button to be used multiple times in one activity

I have a calculator button (=). When I click it the first time, it works great. When I click it subsequent times, it fails - does not update the TextViews on subsequent clicks.

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button viewCalculate = (Button) findViewById(R.id.calculate);
    final TextView viewTimeRemaining = (TextView) findViewById(R.id.editTimeRemaining);
    final TextView viewTimeSaved = (TextView) findViewById(R.id.editTimeSaved);

    final TextView viewMinimumPayment = (TextView) findViewById(R.id.editMinimumPayment);

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

        viewMinimumPayment.setText("" + minPayment);
        viewTimeRemaining.setText("" + nStarting);
        viewTimeSaved.setText("" + nDifference);

            }
        });
    }

}

I took out a lot of irreverent stuff so if it doesn't look like it does anything, it does...

When I click the button it should override the 3 textviews with the updated calculations. When I test it, I am changing the variables in drastic ways so there is a mathematical change.

Any suggestions?

Thanks.

Upvotes: 0

Views: 82

Answers (1)

adhithiyan
adhithiyan

Reputation: 168

I think u have defined the calculation (minPayment and so) in onCreate method. So they are not getting updated. Try to put those calculation inside onclick method so that they are updated. Can you post the entire code or a part of code showing where minPayment is updated.

Upvotes: 2

Related Questions