Attribute | TextView | Button | Button |
---|---|---|---|
id | num_clicks | ||
text | 0 | Click Me | Reset |
layout_width | wrap-content | wrap-content | wrap-content |
layout_height | wrap-content | wrap-content | wrap-content |
layout_margin | 30dp | 30dp | 30dp |
layout_gravity | center | center | center |
textAllCaps | false | false | |
textSize | 100dp | 25dp | 25dp |
onClick | incrementCount | resetCount |
txtCount = findViewById(R.id.txt_num_clicks); if (savedInstanceState != null) { count = savedInstanceState.getInt("clickCount"); } else { count = 0; } txtCount.setText(String.valueOf(count));
@Override public void onSaveInstanceState(Bundle savedInstanceState) { super.onSaveInstanceState(savedInstanceState); savedInstanceState.putInt("clickCount", count); }