Focus issue in ListView EditText display in Dialog in Android
Asked Answered
J

3

11

I have to display ListView contains EditText on Dialog, where a user can type the text in EditText and its content should not be lost.

For example, I have 10 EditText in listview, if the user types "11" in first EditText , "22" in second EditText , "33" in third EditText and scroll down the listview at tenth EditText after that user scroll it up again at first EditText at that time the value in first EditText should be "11", for second EditText "22" and so on, I have achieved this by setting EditText when text gets changed in EditText.

I use NiftyDialog as dialog (Link). The issue is that the EditText got focus randomly (it sometimes worked and sometimes not).

I have set

android:descendantFocusability="afterDescendants"

in ListView and set

android:windowSoftInputMode="adjustPan"

in Manifest File, but its not working properly.

What can be the issue here?

Jilly answered 28/12, 2015 at 6:32 Comment(6)
you need to show the more code!Annotation
Create one activity, show the NiftyDialog (set custom view in that) and in that custom view take listview, take EditText in its row file, take 10 dummy data in ArrayList and set to BaseAdapter than check if you have any focus issue or not.Jilly
@AADTechnical: If you have any suggestions or alternative solution for this issue than please inform me.Jilly
set your listview android:clickable="false" and use your editText android:clickable/touchable ="true" , for listening the touch/click event of editText. And use View holder inside your custom Adapter and then, display the value 11, 22, as EditText hint . Which will not trigger editText textwatcher, editor listeners.Dinosaurian
@Jayesh,i hope it will work for u ,vikaskanani.wordpress.com/2011/07/27/…Claraclarabella
@TheGreat004: It is working perfectly in the activity's xml ListView , but have you a ever try with in Dialog as I want?Jilly
L
1

I had this issue a while ago with EditText focus and realized that just setting the attributes on existing views wont work. In my case it was to avoid the keypad from poping up, but I believe, the same solution will work in your case too.

Add a dummy layout with android:focusable="true" and android:focusableInTouchMode="true" on top above all other views. This way the focus would go to this layout (which is at the top) and your random focus problem with the EditText in the ListView will get resolved.

    <!-- Stop auto focussing the EditText -->
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@android:color/transparent"
        android:focusable="true"
        android:focusableInTouchMode="true">
    </LinearLayout>
Lynda answered 14/1, 2016 at 6:7 Comment(0)
V
0

Use a another list of string type of size 10 and place blank initially of each string now add a textwatcher on edittext and on onTextchange method reassign string value in list for that particular position .Please provide your adapter code will do remaining

Vanettavang answered 12/1, 2016 at 8:35 Comment(2)
I already achieved that, I can hold the entered value in EditText while scrolling up and dwon the listview, the issue is only I don't get cursor in some of the EditText sometime. I can also type in EditText when I clicked it.Jilly
hold the position of last active editfield and if last hold position and getview position is same then set request focus else notVanettavang
D
0

Are you explicitly requesting focus for the EditText? As in myEditText.requestFocus()

From your question, it seems you want the focused edit text to change as the user scrolls down. Can you clarify the behavior you expect and what is occuring?

Doting answered 13/1, 2016 at 21:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.