gpt4 book ai didi

Android onkey - dispatchKeyEvent 未触发

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:17:43 24 4
gpt4 key购买 nike

好吧,我已经尝试了所有我能在 stackoverflow 和其他地方找到的解决方案,但最终结果一点都没有改变:触发 onKey 事件或 dispatchKeyEvent 的唯一键是虚拟键盘,并且只有按下两次。我无法拦截任何其他键(事件顶部有一个断点,并且 Eclipse 永远不会在其上停止,除非是上述输入的情况)。模拟器和真实设备上的行为是相同的。有任何想法吗?先感谢您我的代码 atm 看起来像这样:

public class ChatWindow {

@Override
public void onCreate(Bundle savedInstanceState) {
//...
setSendText();
//...
}

private void setUserInput() {
Intent i = getIntent();
mChatInput = (EditText) findViewById(R.id.UsrInput);
if (i.hasExtra(INTENT_EXTRA_MESSAGE)) {
mChatInput.setText(i.getExtras().getString(INTENT_EXTRA_MESSAGE));
}
mChatInput.setFocusable(true);
mChatInput.requestFocus();
mChatInput.setFocusableInTouchMode(true);

mChatInput.addTextChangedListener(new TextWatcher() {

public void afterTextChanged (Editable s){
Log.d(TAG, "afterTextChanged");
if (mChatInput.getText().length() >= 1) {
mChatInput.addTextChangedListener(this);
//mChatInput.setOnKeyListener(this);
//mChatInput.dispatchKeyEvent(this);
mSendButton.setEnabled(true);
}
else
mSendButton.setEnabled(false);
}

public void beforeTextChanged (CharSequence s, int start, int
count, int after)
{
Log.d(TAG, "beforeTextChanged");
}

public void onTextChanged (CharSequence s, int start, int before,
int count)
{
Log.d(TAG, s.toString());
}


});

}
}

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
//THIS HERE IS NEVER FIRED UNLESS THE ENTER KEY IS CLICKED TWICE
if (event.getAction() == KeyEvent.ACTION_DOWN
&& event.getKeyCode()==KeyEvent.KEYCODE_ENTER) {
sendMessageIfNotNull();
return true;
}

return false;
}

最佳答案

dispatchKeyEvent 仅在 Activity 获得焦点时起作用

关于Android onkey - dispatchKeyEvent 未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12092438/

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