0

I don't know why when I press on parent item for Expand or Collapse the group, other child(s) in other parents will be appear as in refresh state ?

this is the item:

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="55dip"
      android:orientation="vertical" >

    <WebView android:id="@+id/webkit"
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
    />
    </LinearLayout>

and this for the parents:

     <TextView
      android:id="@+id/lblListHeader"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
      android:textSize="17dp"
      android:textColor="#f9f93d" />

    </LinearLayout>

and this is the main_activity.xml:

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical"
     android:background="#f4f4f4" >

        <ExpandableListView
            android:id="@+id/lvExp"
            android:layout_height="match_parent"
            android:layout_width="match_parent"/>   

    </LinearLayout>

and this is the "getChildView" method in ExpandableListAdapter.java "ExpandableListAdapter extends BaseExpandableListAdapter"

      @Override
      public View getChildView(int groupPosition, final int childPosition,
        boolean isLastChild, View convertView, ViewGroup parent) {

       final String childText = (String) getChild(groupPosition, childPosition);

      if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) this._context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.list_item, null);
      }

      WebView webview = (WebView) convertView
            .findViewById(R.id.webkit);

      webview.loadData(childText,
            "text/html", "UTF-8");
      return convertView;
      }

finally this is the main.java:

       // preparing list data
      prepareListData();

    listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);

    // setting list adapter
    expListView.setAdapter(listAdapter);

      private void prepareListData() {
    listDataHeader = new ArrayList<String>();
    listDataChild = new HashMap<String, List<String>>();

    // Adding child data
    listDataHeader.add("Top 250");
    listDataHeader.add("Now Showing");
    listDataHeader.add("Coming Soon..");


    // Adding child data
    String s = "<html><body><b>Hello, world!</b><br />" +
                    "<ul>" +
                    "<li>first</li>"+
                    "</ul>"+
                "</body></html>";
    List<String> top250 = new ArrayList<String>();
    top250.add(s);

    List<String> nowShowing = new ArrayList<String>();
    nowShowing.add(s);

    List<String> comingSoon = new ArrayList<String>();
    comingSoon.add(s);

    listDataChild.put(listDataHeader.get(0), top250); // Header, Child data
    listDataChild.put(listDataHeader.get(1), nowShowing);
    listDataChild.put(listDataHeader.get(2), comingSoon);
    }
Eiad Deeb
  • 187
  • 2
  • 6

1 Answers1

1

I think the problem might be related on how you initialize the view and reuse them in the lists. Do you use the ViewHolder pattern?

maybe this other answer can help you: ListView reusing views when ... I don't want it to

some more links about ViewHolder:

http://developer.android.com/training/improving-layouts/smooth-scrolling.html#ViewHolder

http://www.codeofaninja.com/2013/09/android-viewholder-pattern-example.html

Community
  • 1
  • 1
Noya
  • 3,879
  • 3
  • 26
  • 32