gpt4 book ai didi

Android View.OnKeyListener : click once, 执行两次

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:06:35 28 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
public boolean onKey() called twice?

这是我的代码

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;
}
});
}
}

我用的是安卓模拟器和Eclipse,不知道为什么,点击一下按键,代码toast 将执行两次。我的代码有问题吗?

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com