主要code_Enter到明年的EditText明年、code_Enter、EditText

2023-09-13 23:48:14 作者:无声无息。安之若素╮

在EditText上,输入后回车键,系统使里面的新行。我想专注于接下来的EditText,没有新的生产线。如何code?我的code在XML低于

 <的EditText
    机器人:ID =@ + ID / txtNP code
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:TEXTSIZE =18sp
    机器人:layout_alignLeft =@ + ID / lblNP code
    机器人:layout_below =@ + ID / lblNP code
    机器人:layout_centerHorizo​​ntal =真
/>
<的EditText
    机器人:ID =@ + ID / txtCNP code
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:TEXTSIZE =18sp
    机器人:layout_alignLeft =@ + ID / lblCNP code
    机器人:layout_below =@ + ID / lblCNP code
    机器人:layout_centerHorizo​​ntal =真
    />
 

我也caputer键code在setOnKeyListener

  tCNP code.setOnKeyListener(新OnKeyListener(){公共布尔onKey(视图V,INT关键code,KeyEvent的事件){
// TODO自动生成方法存根
如果(键code == 66)
{Toast.makeText(S_P code.this,
   回车键,
   Toast.LENGTH_LONG).show();
//tNP$c$c.setFocusable(true);
}
返回false; }});
 
解决遇到的问题并在vscode上测试

解决方案

您必须使用requestFocus方法。在你的情况下,它会是这样的:

  tCNP code.setOnKeyListener(新OnKeyListener(){
    公共布尔onKey(视图V,INT关键code,KeyEvent的事件){
        如果(键code == 66){
            txtCNP code.requestFocus();
        }
        返回false;
    }
});
 

In edittext, after typing 'Enter' key, system make a new line inside it. I'd like to focus on next edittext, no new line. how to code? my code in xml is below

    <EditText
    android:id="@+id/txtNPCode"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="18sp"
    android:layout_alignLeft="@+id/lblNPCode"
    android:layout_below="@+id/lblNPCode"
    android:layout_centerHorizontal="true"
/>
<EditText
    android:id="@+id/txtCNPCode"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="18sp"
    android:layout_alignLeft="@+id/lblCNPCode"
    android:layout_below="@+id/lblCNPCode"
    android:layout_centerHorizontal="true"
    />  

I also caputer key code in setOnKeyListener

        tCNPCode.setOnKeyListener(new OnKeyListener() {    public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if(keyCode == 66)
{ Toast.makeText(S_PCode.this, 
   "Enter Key",                 
   Toast.LENGTH_LONG).show();
//tNPCode.setFocusable(true);    
}
return false;   }  });

解决方案

You have to use the requestFocus method. In your case it will be something like:

tCNPCode.setOnKeyListener(new OnKeyListener() {
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        if(keyCode == 66) {
            txtCNPCode.requestFocus();
        }
        return false;
    }
});