Android 为什么赢了';是否处理列表的EditText的enter事件?
我有一个EditText、一个listview和一个按钮“Add”。我希望这样,当用户点击键盘上的enter/return/add按钮时,它会执行与“add”相同的操作。它应该通过调整arrFencer字符串Arraylist并通知连接的适配器“adapter”,将输入的字符串值添加到listview 然而,当我编写这段代码时,AVD只是最小化了键盘,而没有将其添加到listview中。我做错了什么Android 为什么赢了';是否处理列表的EditText的enter事件?,android,keyboard,android-edittext,Android,Keyboard,Android Edittext,我有一个EditText、一个listview和一个按钮“Add”。我希望这样,当用户点击键盘上的enter/return/add按钮时,它会执行与“add”相同的操作。它应该通过调整arrFencer字符串Arraylist并通知连接的适配器“adapter”,将输入的字符串值添加到listview 然而,当我编写这段代码时,AVD只是最小化了键盘,而没有将其添加到listview中。我做错了什么 //setup name Actions final EditText name
//setup name Actions
final EditText nameEditText = (EditText) findViewById(R.id.txtName);
nameEditText.setImeActionLabel("Add", KeyEvent.KEYCODE_ENTER);
//add the name when Enter is hit
nameEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_NEXT) {
//add name to list
arrFencers.add(nameEditText.getText().toString());
adapter.notifyDataSetChanged();
nameEditText.setText("");
handled = true;
}
return handled;
}
});
编辑:仅供参考editText有一个android:imeOptions=“actionNext”
设置这可能有助于:
if (actionId == EditorInfo.IME_ACTION_SEARCH ||
(event != null && event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER))
首先在你的编辑器操作中输入一个日志,看看它是否被点击,这样你就知道这是适配器问题还是键盘问题。我已经设置了“android:imeOptions=“actionNext,并且actionID与IME\u ACTION\u NEXT code/ID不匹配。我没有正确设置它吗?如果在if语句上放置一个断点,并在按下NEXT按钮时点击它,ACTION ID的值是多少?actionID=66,IME\u ACTION\u NEXT=5hmm。您是否尝试过在xml中设置edittext的ime操作而不是代码