以编程方式更改EditText IME_ACTION

Ped*_*dro 8 android

在我的应用程序中,我需要显示一个或两个edittexts来收集信息(e1和e2),具体取决于用户通过radiobutton进行的选择.这是通过将edittext的可见性状态设置为GONE来完成的,并且工作正常.

我的问题是如何以编程方式为每种情况将IME_ACTION从"完成"设置为"下一步",即:

1)只有e1可见 - 将e1的IME_ACTION设置为DONE

2)e1和e2是可见的 - 将e1的IME_ACTION设置为NEXT,将e2的IME_ACTION设置为DONE.

我正在使用android:minSdkVersion ="4"和android:targetSdkVersion ="16"并在Android 2.2设备上进行测试.

这是我的布局:

<EditText
android:id="@+id/e1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:inputType="text"
android:maxLines="1"
android:singleLine="true"
android:imeOptions="actionDone"
android:hint="@string/sh15"
android:textColor="@android:color/black"
android:textSize="@dimen/s">
</EditText>         
<EditText
android:id="@+id/e2"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:inputType="text"
android:maxLines="1"
android:singleLine="true"
android:imeOptions="actionDone"
android:hint="@string/sh16"
android:textColor="@android:color/black"
android:textSize="@dimen/s">
</EditText> 
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

RadioGroup r= (RadioGroup) dialog.findViewById(R.id.rg);
  r.setOnCheckedChangeListener(new OnCheckedChangeListener() 
  {
   public void onCheckedChanged(RadioGroup group, int checkedId) 
   {
    switch(checkedId)
    {
     case R.id.rb1: //show one edittext
         e1.setVisibility(View.VISIBLE);             
         e2.setVisibility(View.GONE);
         e1.setImeOptions(EditorInfo.IME_ACTION_DONE);
     break;
     case R.id.rb2: //show two edittext
         e1.setVisibility(View.VISIBLE);
         e2.setVisibility(View.VISIBLE);
         e1.setImeOptions(EditorInfo.IME_ACTION_NEXT);
         e2.setImeOptions(EditorInfo.IME_ACTION_DONE);
     break;

    }
   }
  });  
Run Code Online (Sandbox Code Playgroud)

Quo*_*oon 6

e2.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Overrid
    public boolean onEditorAction(TextView v, int actionId,KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_DONE) {
                //your code    
              }
          }
)};
Run Code Online (Sandbox Code Playgroud)