I am new to android, please help me to get the solution for this question.
I need to update TextView of my android application when the user clicks volume up button, each time when user clicks the button the count has to increment like 1,2,3,4,5... for this I have done as follows
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int action = event.getAction();
int keyCode = event.getKeyCode();
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
if (action == KeyEvent.ACTION_DOWN) {
int current = Integer.parseInt((String)counter_view.getText());
counter_view.setText(current+1+"");
}
return true;
default:
return super.dispatchKeyEvent(event);
}
}
This code is working but the problem with this is textview updates in very slow,if I press the button continuously then it takes little time to update textview .is there any another method to do this ?