0

I have a expandable listview.on expanding a group i am getting child views with a footer which has an edit text.Now when i write something in that edit text and when i scroll up/down the text written inside it gets blanked.So i have followed this link collasping

expandable-listview it works but that at one time i am expanding one group but how to keep the values intact even when scrolling and clear its when when group gets collapsed..any help please. heres my childview code

public View getChildView(int gposition, int childposition, boolean isLastChild, View arg3, ViewGroup arg4) {
    // TODO Auto-generated method stub

    LayoutInflater inf=getLayoutInflater();


    if(childposition == 0)return arg3 = inf.inflate(R.layout.child_header, null);

    if(isLastChild){
        arg3 = inf.inflate(R.layout.child_footer, null);
    }

in this child footer i have an edittext.

Community
  • 1
  • 1

1 Answers1

0

Take a look at this link, it is quite simple, and explain quite well the solution to your problem (it's not am expandablelistview, but the theory is the same).

The core problem is:

You can’t save anything on ListView Item. You must need to handle another data-source that maintain your changes in ListView’s item.

This is the part of the code that do the job:

 //Fill EditText with the value you have in data source
 holder.caption.setText(myItems.get(position).caption);
 holder.caption.setId(position);

 //we need to update adapter once we finish with editing
 holder.caption.setOnFocusChangeListener(new OnFocusChangeListener() {
       public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus){
                  final int position = v.getId();
                  final EditText Caption = (EditText) v;
                  myItems.get(position).caption = Caption.getText().toString();
            }
       }
 });

You just have to create a myItems that is not a simple list but a List<List> or a Map<String, List>.

For the collapsing of the group take a look at this answer, i think it's more efficient than the loop one

Also take a look at this video it will improve a lot design and performance of your listview/expandablelistview

Community
  • 1
  • 1