变化的EditText IME_ACTION编程EditText、IME_ACTION

2023-09-06 04:00:43 作者:青春期的烦恼

在我的应用程序,我需要显示一个或两个edittexts收集信息(E1和E2),这取决于选择的用户将通过做一个单选按钮。这是由EditText上的可见性状态设置为走了,工作正常进行。

我的问题是如何通过编程设置为从IME_ACTION做到下一个为每一种情况下,即:

1)只有E1可见 - 设置E1的IME_ACTION来完成

2)E1和E2是可见的 - 集E1的IME_ACTION E2对NEXT和IME_ACTION来完成

我使用的是安卓的minSdkVersion =4和android:targetSdkVersion =16和测试Android 2.2的设备上

下面是我的布局:

 <的EditText
机器人:ID =@ + ID / E1
机器人:layout_width =0dip
机器人:layout_height =WRAP_CONTENT
机器人:inputType =文本
机器人:MAXLINES =1
机器人:单线=真
机器人:imeOptions =actionDone
机器人:提示=@字符串/ SH15
机器人:文字颜色=@机器人:彩色/黑白
机器人:TEXTSIZE =@扪/秒>
< /的EditText>
<的EditText
机器人:ID =@ + ID / E2
机器人:layout_width =0dip
机器人:layout_height =WRAP_CONTENT
机器人:inputType =文本
机器人:MAXLINES =1
机器人:单线=真
机器人:imeOptions =actionDone
机器人:提示=@字符串/ SH16
机器人:文字颜色=@机器人:彩色/黑白
机器人:TEXTSIZE =@扪/秒>
< /的EditText>
 
Mac 上的 Web 开发者最喜欢的编程工具 Linux 中国 技术无边 CSDN博客 本地环境 local 在做web开发时,通常最好

下面是我的code:

  RadioGroup中R =(RadioGroup中)dialog.findViewById(R.id.rg);
  r.setOnCheckedChangeListener(新OnCheckedChangeListener()
  {
   公共无效onCheckedChanged(RadioGroup中组,诠释checkedId)
   {
    开关(checkedId)
    {
     案例R.id.rb1://分别用的EditText
         e1.setVisibility(View.VISIBLE);
         e2.setVisibility(View.GONE);
         e1.setImeOptions(EditorInfo.IME_ACTION_DONE);
     打破;
     案例R.id.rb2://显示两个的EditText
         e1.setVisibility(View.VISIBLE);
         e2.setVisibility(View.VISIBLE);
         e1.setImeOptions(EditorInfo.IME_ACTION_NEXT);
         e2.setImeOptions(EditorInfo.IME_ACTION_DONE);
     打破;

    }
   }
  });
 

解决方案

  e2.setOnEditorActionListener(新TextView.OnEditorActionListener(){
        @Overrid
    公共布尔onEditorAction(TextView的V,INT actionId,KeyEvent的事件){
        如果(actionId == EditorInfo.IME_ACTION_DONE){
                //你的code
              }
          }
)};
 

In my app I need to display one or two edittexts to collect information (e1 and e2), depending on the selection the user will do through a radiobutton. This is done by setting the visibility state of the edittext to GONE and works fine.

My problem is how to programmatically set the IME_ACTION from "done" to "next" for each case, i.e.:

1) Only e1 is visible - set IME_ACTION of e1 to DONE

2) e1 and e2 are visible - set IME_ACTION of e1 to NEXT and IME_ACTION of e2 to DONE.

I'm using android:minSdkVersion="4" and android:targetSdkVersion="16" and testing on a Android 2.2 device.

Here's my layout:

<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> 

Here's my code:

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;

    }
   }
  });  

解决方案

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