EditTexts inside ExpandableListView

Hey. I am trying to do an operation that displays an ExpandableListView as shown.

When you click on a group, it expands and displays a LinearLayout with text and editext.

I know correctly that the problem is that when I click on EditText it does not receive focus, and I have to double-click on it to get it to get focus and display the keyboard, and then when I enter the text, I see nothing at first input time, and then when I hide the keyboard, EditText is updated with the text I typed

I tried adding android: descendantFocusability = "afterDescendants" to the expandableListVie layout, but the behavior is the same.

Any idea? or any other way I could implement this layout

Expandable ListView with EditText

+4
source share
4 answers

add this to the manifest immediately after the android: name in your activity

android:windowSoftInputMode="adjustPan" 
+6
source

I'm not sure how to fix the focus problem, but I know why you need to collapse and expand the group to see the text in editText. The list is not updated unless you scroll or do something like expanding and collapsing the list. Therefore, the best way to solve this problem is to create a list of strings that will be the editTexts values ​​in the listview. Then create an onKeyClick () listener for each of the editTexts and do the following:

 editText1.setOnKeyListener(new EditText.OnKeyListener() { public boolean onKey(View editText, int keyCode, KeyEvent keyEvent) { // Get the position of the item somehow int position = 4; // Get value from List<String> for editTexts String textValue = listOfValues.get(position); textValue = ((EditText)editText).getValue(); adapter.notifyDataSetChanged(); return false; } }); 

What happens here is that you get the editText value after pressing the key and change the value of the line in the list to a new value. Then you tell the adapter that the value of one of the elements has changed, and it should be updated. Although this is not an effective way to fix the problem, it is a backup solution if you cannot come up with a better way.

+1
source

Try saving the values ​​in the Edittext variable to String using the function

 String temp; editText.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } public void afterTextChanged(Editable s) { // TODO Auto-generated method stub temp = s.toString();//editText.getText().toString(); childValues[groupPosition][childPosition][]= temp ; Toast.makeText(context, ""+childValues[groupPosition][childPosition], Toast.LENGTH_SHORT).show(); } }); 

and in the getChild() function, always check the data in the temp and settext() parameters for this particular edittext .

+1
source

You need to add two things.

1) expandableListView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

2) In the manifest (according to your activity) android:windowSoftInputMode="adjustPan"

0
source

All Articles