android - How to change the focus from last edit text field to a button on clicking done in soft input? -


i want change focus edit-text field submit button when done clicked on soft input.

i've following code :

<linearlayout     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:orientation="horizontal"     android:paddingtop="5sp">      <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="driver + conductor :"         android:textsize="17sp"         android:textstyle="bold" />      <edittext         android:id="@+id/bus_driver_above60"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_marginleft="5dp"         android:layout_weight="1"         android:hint="driver"         android:inputtype="numberdecimal"         android:textalignment="center"         android:textcolor="#000"         android:nextfocusdown="@+id/bus_conductor_above60"/>      <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_marginleft="2dp"         android:text="+"         android:textsize="17sp"         android:textstyle="bold" />      <edittext         android:id="@+id/bus_conductor_above60"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_marginleft="2dp"         android:layout_weight="1"         android:hint="conductor"         android:inputtype="numberdecimal"         android:textalignment="center"         android:textcolor="#000"         android:nextfocus="@+id/bus_above60_btn"/>  </linearlayout>  <button     android:id="@+id/bus_above60_btn"     android:layout_width="match_parent"     android:layout_height="50dp"     android:text="calculate"     android:textsize="17sp"     android:textcolor="#ffffff"     android:textstyle="bold"     android:background="#3498db"/> 

here in code,

android:nextfocusdown="@+id/bus_conductor_above60"  

changes focus driver edit text field conductor edit text field.

but after conductor edit text field, there calculate button - bus_above60_btn.

android:nextfocusdown="@+id/bus_above60_btn"  

is not changing focus conductor edit text field button below field.

how achieve this?

if want make button focused on done action, first must set buttons focusableintouchmode true

<button     android:id="@+id/bus_above60_btn"     android:layout_width="match_parent"     android:layout_height="50dp"     android:text="calculate"     android:focusableintouchmode="true"     android:textsize="17sp"     android:textcolor="#ffffff"     android:textstyle="bold"     android:background="#3498db"/> 

now in edittext's oneditoractionlistener, make button focused when done clicked:

bus_conductor_above60.setoneditoractionlistener(new textview.oneditoractionlistener() {     @override     public boolean oneditoraction(textview textview, int action, keyevent keyevent) {         if(action == editorinfo.ime_action_done)             bus_above60_btn.requestfocus();         return false;     } }); 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -