Possible duplicate:
public boolean onKey () is called twice?
Here is my code
public class TestKeyActivity extends Activity {
private int i=1;
private ScrollView sv;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
sv=(ScrollView) this.findViewById(R.id.read_scrollView);
sv.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
Toast.makeText(TestKeyActivity.this, "what is wrong!!!!"+(i++), 2).show();
return true;
}
return false;
}
});
}
}
I use its Android emulator and Eclipse, I don’t know why, but when I press the key once, the toast code will be executed twice. Is there something wrong with my code?
source
share