当我尝试使用Android-PullToRefresh库时遇到此错误: https://github.com/chrisbanes/Android-PullToRefresh
1255-1255/cn.thu.uems E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{cn.thu.uems/cn.thu.uems.MainUI}: java.lang.RuntimeException: Your content must have a ExpandableListView whose id attribute is 'android.R.id.list'
这是我的XML文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#eee"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="45dp"
android:id="@+id/title"
android:background="@drawable/title_bar"
android:gravity="center_vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="State"
android:layout_centerInParent="true"
android:textSize="20sp"
android:textColor="#ffffff" />
<Button
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:text="History"
android:textColor="#fff"
android:textSize="15dp"
android:background="@drawable/title_btn_right"
/>
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.handmark.pulltorefresh.library.PullToRefreshExpandableListView
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="@+id/pull_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
</LinearLayout>
这是我的代码相关:
mPullToRefreshView = (PullToRefreshExpandableListView) findViewById(R.id.pull_list);
mPullToRefreshView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<ExpandableListView>() {
@Override
public void onRefresh(PullToRefreshBase<ExpandableListView> expandableListViewPullToRefreshBase) {
new GetDataTask().execute();
}
});
lvadapter = new LoadsViewAdapter(this, groupEntity, childEntity);
ExpandableListView ActualView = mPullToRefreshView.getRefreshableView();
ActualView.setAdapter(lvadapter);
PS:我没有扩展ListActivity或ExpandableListActivity,所以将ID更改为@android:id / list对我不起作用。
HELP!这个问题让我感到不舒服!
答案 0 :(得分:0)
我认为您可以将适配器设置为mPullToRefreshView本身,因为它已经是可扩展的列表视图..(see at library you are using)
mPullToRefreshView.setAdapter(lvadapter);
并删除或评论此内容。
ExpandableListView ActualView = mPullToRefreshView.getRefreshableView();
Gud Luck .. :))