[英]Android - Edittext soft keyboard
我有一个带有EditText
的ListView
; 当我触摸EditText
,将出现软键盘,并且我输入了一些文本,这很好。 但是在输入文本后,按退格按钮(而不是后退按钮),活动将结束。
为什么会发生? 这里出了什么问题? 我该如何解决? 请有人帮我找出这个谜语。
在xml中。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minLines="15"
android:textColor="#000000"
android:background="@drawable/back"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comments"
android:textColor="#000000"
android:visibility="gone"/>
<TextView
android:id="@+id/notes_to_parents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
</LinearLayout>
在Java中。 此for循环在Listview onScroll Action内部。
for (int i = 0; i < daily_dairy_2.getChildCount(); i++)
{
LinearLayout layout = (LinearLayout) daily_dairy_2.getChildAt(i);
final EditText notes_to = (EditText) layout.getChildAt(0);
}
我知道在这里我没有为edittext写任何代码。 如何处理此edittext。
您可以为editText设置OnKeyListener,以便可以检测到任何按键
editText.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
//You can identify which key pressed buy checking keyCode value with KeyEvent.KEYCODE_
if(keyCode == KeyEvent.KEYCODE_DEL){
//this is for backspace
}
return false;
}
});
这是代码句柄退格按钮
按退格键制作自己的实现。
是这样的
public final static int CodeDelete = -5;
public class MyKeyboard extends InputMethodService
implements OnKeyboardActionListener{
public void onKey(int primaryCode, int[] keyCodes) {
InputConnection ic = getCurrentInputConnection();
switch(primaryCode){
case CodeDelete :
ic.deleteSurroundingText(1, 0);
break;
并在键盘的xml中:
<Key android:codes="-5" android:keyIcon="@drawable/sym_keyboard_delete_dim">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.