2012-12-04 35 views
5

Trong ứng dụng của tôi, tôi có một màn hình đăng ký, Có rất nhiều EditTexts và Spinners. Tôi muốn đi qua từng trường Đăng ký.Android: EditText NextFocusDown không kích hoạt Spinner

Vì vậy, tôi đã áp dụng android:imeOptions="actionNext". Nhưng nó bỏ qua tất cả các Spinners. Nó sẽ chỉ tập trung vào EditText. Tôi cũng đã thử setNextFocusDownId(). Điều này cũng bỏ qua các spinners.

<LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/reportentry11" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     <EditText 
      android:id="@+id/numbers" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 

      android:imeOptions="actionNext" 
      android:inputType="phone" 
      > 
      <requestFocus/> 
     </EditText> 

     <LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/reportentry12" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      > 

      <TextView 
       android:id="@+id/txt_exp" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 

       android:text="EXP:" 
       android:textColor="#000000" 
       android:textSize="12dp" /> 

      <Spinner 
       android:id="@+id/spin_date" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="3" 
       android:focusable="true" 
       android:focusableInTouchMode="true" 
       android:nextFocusDown="@+id/spin_year" 
       android:text="date" 
       android:textSize="12dp" /> 

      <Spinner 
       android:id="@+id/spin_year" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_marginRight="5dp" 

        android:nextFocusDown="@+id/cvc" 
       android:text="year" 
       android:textSize="12dp" /> 
     </LinearLayout> 

     <EditText 
      android:id="@+id/cvc" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:hint="@string/reg_label_cvc" 
      android:imeOptions="actionNext" 
      android:inputType="phone" /> 

     <EditText 
      android:id="@+id/fname" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:hint="@string/reg_label_fname" 
      android:imeOptions="actionNext" /> 

     <EditText 
      android:id="@+id/address" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:hint="@string/reg_label_address" 
      android:imeOptions="actionNext" /> 

     <EditText 
      android:id="@+id/city" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:hint="@string/reg_label_city" 
      android:imeOptions="actionNext" 
      android:nextFocusDown="@+id/pr_spin" /> 

     <LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/reportentry13" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" > 

      <TextView 
       android:id="@+id/txt_pr" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:text="PROV:" 
       android:textColor="#000000" 
       android:textSize="12dp" /> 

      <Spinner 
       android:id="@+id/pr_spin" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:text="date" 
       android:imeOptions="actionNext" 
       android:textSize="14dp" /> 

      <EditText 
       android:id="@+id/pcode" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:hint="@string/reg_label_pcode" 
       android:imeOptions="actionDone" /> 
     </LinearLayout> 

     <Button 
      android:id="@+id/register_register_button" 
      android:layout_width="wrap_content" 
      android:background="@drawable/green_button_bg" 
      android:onClick="completeClicked" 
      android:text="@string/reg_label_complete" 
      android:textSize="28dp" 
      android:textStyle="bold" /> 
    </LinearLayout> 

Vui lòng cung cấp cho tôi cách tốt nhất để kích hoạt spinners.

+0

Tôi nghĩ rằng liên kết này sẽ giúp bạn .... [link] [1] [1]: http: //stackoverflow.com/questions/6443212/spinner-did-not-got-focus Cảm ơn ... – user4232

Trả lời

4

On chỉnh sửa văn bản của bạn, ghi đè onEditorAction và đưa ra tập trung (hoặc làm bất cứ điều như mở spinner của bạn) ...

yourEditTXT.setOnEditorActionListener(new OnEditorActionListener() { 
    @Override 
    public boolean onEditorAction(TextView view, int actionID, KeyEvent event) { 
      if (actionID == EditorInfo.IME_ACTION_NEXT) { 
       //do your stuff here... 
       return true; 
      } 
      return false; 
    } 
});  

Sửa 12/4: tôi thấy bạn vẫn còn phải vật lộn với điều này như của cuối cùng ban đêm, nếu bạn không tìm thấy giải pháp (và không đăng một giải pháp) hoặc để giúp những người khác có thể đọc nội dung này, điều này có thể giúp bạn nhận được từ spinner để chỉnh sửa văn bản.

mySpinner.setOnItemSelectedListener(new MyOnItemSelectedListener());    

public class MyOnItemSelectedListener implements OnItemSelectedListener { 

     public void onItemSelected(AdapterView<?> parentview, View v, int position, long id) { 
      // your spinner proces code 
      // then when you are done, 
      yourEditText.setFocusableInTouchMode(true); //if this is not already set 
      yourEditText.requestFocus(); //to move the cursor 
      final InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); 
      inputMethodManager.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT); // this line and the one above will open the soft keyboard if it doesn't already open 
     } 

     public void onNothingSelected(AdapterView<?> arg0) { } 
    }; 
+0

Danh sách spinner đang hoạt động nhưng bật lên của nó không hiển thị, chỉ spinner là làm nổi bật – Sridhar

+0

những gì @GMRamesh cho biết cộng với yourWidget.performClick() nên thực hiện thủ thuật. – logray

+0

mã của bạn để chuyển edittext sang spinner đang hoạt động, cung cấp mã cho spinner cho edittext – Sridhar

2

làm như sau trong file xml của bạn:

<Spinnner 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:nextFocusDown="@+id/youedittextid" 
/> 
+0

@GM Ramesh, Nó không hoạt động ... – Sridhar

+0

nó đã làm việc cho tôi ... kiểm tra mã của bạn kỹ lưỡng và thay đổi cho phù hợp ... nó không giống như vậy nếu bạn sao chép dán câu trả lời ở trên nó sẽ hoạt động ... bạn phải thực hiện thay đổi cho phù hợp bạn –

+0

cùng với câu trả lời của tôi, thêm câu trả lời @logray cũng ... nó có thể hoạt động –

Các vấn đề liên quan