我不知道为什么当我按下父项目展开或折叠该组时,其他孩子 其他父母会出现在刷新状态吗?
这是项目:
<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>
这对于父母来说:
<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>
这是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>
这是ExpandableListAdapter.java中的“getChildView”方法“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;
}
最后这是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);
}
答案 0 :(得分:1)
我认为问题可能与您如何初始化视图并在列表中重用它们有关。 你使用ViewHolder模式吗?
也许这个其他答案可以帮到你:ListView reusing views when ... I don't want it to
有关ViewHolder的更多链接:
http://developer.android.com/training/improving-layouts/smooth-scrolling.html#ViewHolder
http://www.codeofaninja.com/2013/09/android-viewholder-pattern-example.html