I have a randomly generated integer displayed on the screen and when the user clicks a button, I want that number to update with a new number or stay the same (depending on which button), but staying on the same activity.
How is the value refreshed/updated while staying on the same activity?
public class ClassName extends Activity implements OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_name);
int currentNum = randNum();
TextView myTextView = (TextView) findViewById(R.id.current_number);
myTextView.setText("Current Number: " + String.valueOf(currentNum));
okButton = (Button) findViewById(R.id.num_confirmation);
okButton.setOnClickListener(this);
changeButton = (Button) findViewById(R.id.change_num);
changeButton.setOnClickListener(this);
// set 'currentNumber' accordingly
// reprint value
}
@Override
public void onClick(View v) {
}
One of the things I want to do is maintain the same value when a button is clicked (i.e. currentNum stays the same). The other thing is to change the value (with a different button click) with a method I have that returns a new number (i.e. currentNumber = methodCall();).
How is this done?
just do this