2012-12-04 16 views
5

W mojej aplikacji mam jeden ekran rejestracyjny, istnieje wiele EditTexts i Spinners. Chcę przejść przez pole Rejestracje jeden po drugim.Android: EditText NextFocusDown nie wyzwala Spinner

Złożyłem więc android:imeOptions="actionNext". Ale Ignoruje wszystkich Prządków. To skupi się tylko na EditText. Próbowałem również setNextFocusDownId(). To również ignoruje spinnerów.

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

Podaj mi najlepszy sposób na wywołanie błystek.

+0

Myślę ten link pomoże .... [LINK] [1] [1]: http: //stackoverflow.com/questions/6443212/spinner-did-not-got-focus Dzięki ... – user4232

Odpowiedz

4

W tej edycji tekstów, zastępują onEditorAction i dać ostrość (lub zrobić cokolwiek jak otwarte Twój spinner) ...

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; 
    } 
});  

Edit 12/4: Widzę, że wciąż zmaga się z tym jak z ostatniego noc, jeśli nie znalazłeś rozwiązania (i nie opublikowałeś) lub nie pomogłeś innym osobom, które mogą to przeczytać, to może pomóc dostać się od pokrętła do edycji tekstu.

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

Działa, ale nie wyświetla się lista spinnerów, tylko spinner jest podświetlony – Sridhar

+0

co @GMRamesh powiedział plus yourWidget.performClick() powinno załatwić sprawę. – logray

+0

Twój kod do przejścia edittext do spinnera działa, podaj mi kod dla spinnera do edittext – Sridhar

2

wykonaj następujące czynności w pliku XML:

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

@GM Ramesh, To nie działa ... – Sridhar

+0

to działało dla mnie ... sprawdź z kodem dokładnie i zmień odpowiednio ... nie jest tak, jeśli skopiujesz wkleić powyższą odpowiedź powinna działać ... musisz wprowadzić odpowiednie zmiany ty –

+0

wraz z moją odpowiedzią, dodaj @logray też odpowiedz ... to może zadziałać –