EditTexts inside ExpandableListView

一世执手 提交于 2019-12-05 16:33:32

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

 android:windowSoftInputMode="adjustPan"

I am not sure how to fix the focusing problem, but I know why you have to collapse and expand the group to see the text in the editText. The listview doesn't refresh unless you scroll or you do something like expanding and collapsing the listview. So the best way I can think of to fix this problem is to create a list of strings that will be the values of the editTexts in the listview. Then create a onKeyClick() listener for each of the editTexts and do this:

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 are getting the value of the editText once a key has been pressed, and are changing the value of the string in the list to the new value. Then you are telling the adapter that the value of one of the items has changed an it needs to refresh. Although this is not an efficient way to fix the problem, it is a backup solution in case you can't think of a better way.

Navya Ramesan

Try to store the values in the Edittext to a String variable 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 for the data in temp and settext() value to that particular edittext.

You have to add two things.

1) expandableListView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

2)In manifest(on your activity) android:windowSoftInputMode="adjustPan"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!