krsb krsb - 25 days ago 22
Android Question

Numeric edittext loses focus after first input in listview

I have multiple edittexts in my listview, numeric and normal. When I click on a numeric it gets the focus and pops up the keypad but after I enter 1 number, it loses its focus and I have to click on it again to enter more numbers. Is there a way to keep focus so I can enter more numbers? My normal edittext works perfectly.

I have already tried with adjustpan and different keyboard modes.

edittext code:

<EditText
android:id="@+id/etEditTextItem"
android:inputType="number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="5"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_alignParentRight="true" />


Listview code:

<ExpandableListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/colorCard"
android:groupIndicator="@null">
</ExpandableListView>

Answer

I managed to fix it, after debugging the currentFocus i found out that the listview onExpand() took the focus away, setting editText.requestfocus() after returned the focus to the edittext.

Comments