2012-09-19 47 views
8

在我的應用程序中,我需要顯示一個或兩個edittext來收集信息(e1和e2),具體取決於用戶通過單選按鈕進行的​​選擇。這是通過將edittext的可見性狀態設置爲GONE並且正常工作來完成的。以編程方式更改EditText IME_ACTION

我的問題是如何通過編程設定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> 

這裏是我的代碼:

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; 

    } 
    } 
    }); 
+0

得到了任何解決方案? –

回答

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

對不起,我不明白你的想法。我需要的是一種從IME_ACTION_DONE更改爲IME_ACTION_NEXT的方法,具體取決於可見的edittext數量。 – Pedro

1

如果有人土地位置:EditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);和上帝幫助你,如果它的TouchWiz :)

而且,如果EditText具有焦點時無法切換,我注意到了問題,因此請確保關閉ke yboard and rescind focus

+0

This is not working.imeOption dint change – Sudhasri

+0

@Sudhasri您正在測試的設備規格是什麼? – AllDayAmazing

+0

我在三星銀河注2中試過這個。 – Sudhasri