这是我的问题:
private PullToRefreshListView listView_;
public void onActivityCreated(Bundle savedInstanceState)
{
listView_ = (PullToRefreshListView) view_.findViewById(R.id.lista_tuoivincoli_refresh);
LayoutInflater inflater = (LayoutInflater) context_.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout listViewFooter = (LinearLayout) inflater.inflate(R.layout.contodeposito_tuoivincoli_tabella_vincoli_footer, listView_, false);
ListView tempView = listView_.getRefreshableView();
tempView.addFooterView(listViewFooter);
...
}
我在这个列表中,里面有一些信息。在页脚中,我得到数字并显示总数。 首先,listView_是一个简单的ListView,而且每个方面都很有效。 将我的xml更改为:
<com.handmark.pulltorefresh.library.PullToRefreshListView
android:id="@+id/lista_tuoivincoli_refresh"
android:layout_width="360dp"
android:layout_height="300dp"
android:layout_marginTop="6dp"
android:divider="@android:color/transparent"
android:dividerHeight="6dp"
android:fadingEdge="none"
android:fastScrollEnabled="false"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false"
android:smoothScrollbar="true" />
将第一行从ListView更改为&#34; com.handmark.pulltorefresh ....&#34; 并添加最后5行(由pulltorefresh库使用。
如果我评论该行
tempView.addFooterView(listViewFooter);
项目运作完美,刷新也有效。
我尝试添加一个带有Handler的postDelayed:
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
LayoutInflater inflater = (LayoutInflater) context_.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout listViewFooter = (LinearLayout) inflater.inflate(R.layout.contodeposito_tuoivincoli_tabella_vincoli_footer, listView_, false);
ListView tempView = listView_.getRefreshableView();
tempView.addFooterView(listViewFooter);
}
}, 3000);
但这不起作用。
我看到的其他问题(我看到很多)建议使用getRefreshableView(),但我已经使用过了。
当他给页脚充气时项目崩溃。
谢谢!
编辑:登录CAT
007-01 12:42:17.530: E/AndroidRuntime(8286): FATAL EXCEPTION: main
07-01 12:42:17.530: E/AndroidRuntime(8286): java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.widget.ListView.clearRecycledState(ListView.java:513)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.widget.ListView.resetList(ListView.java:500)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.widget.ListView.layoutChildren(ListView.java:1474)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.widget.AbsListView.onLayout(AbsListView.java:2052)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.View.layout(View.java:11477)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.ViewGroup.layout(ViewGroup.java:4232)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.View.layout(View.java:11477)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.ViewGroup.layout(ViewGroup.java:4232)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1644)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1502)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.widget.LinearLayout.onLayout(LinearLayout.java:1415)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.View.layout(View.java:11477)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.ViewGroup.layout(ViewGroup.java:4232)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1644)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1502)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.widget.LinearLayout.onLayout(LinearLayout.java:1415)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.View.layout(View.java:11477)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.ViewGroup.layout(ViewGroup.java:4232)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:925)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.View.layout(View.java:11477)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.ViewGroup.layout(ViewGroup.java:4232)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.View.layout(View.java:11477)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.ViewGroup.layout(ViewGroup.java:4232)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1644)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1633)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.widget.LinearLayout.onLayout(LinearLayout.java:1417)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.View.layout(View.java:11477)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.ViewGroup.layout(ViewGroup.java:4232)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:925)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.View.layout(View.java:11477)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.ViewGroup.layout(ViewGroup.java:4232)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.View.layout(View.java:11477)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.ViewGroup.layout(ViewGroup.java:4232)
07-01 12:42:17.530: E/AndroidRuntime(8286): at net.simonvt.menudrawer.LeftDrawer.onLayout(LeftDrawer.java:62)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.View.layout(View.java:11477)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.ViewGroup.layout(ViewGroup.java:4232)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.View.layout(View.java:11477)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.ViewGroup.layout(ViewGroup.java:4232)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1644)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1502)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.widget.LinearLayout.onLayout(LinearLayout.java:1415)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.View.layout(View.java:11477)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.ViewGroup.layout(ViewGroup.java:4232)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.View.layout(View.java:11477)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.ViewGroup.layout(ViewGroup.java:4232)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1692)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2649)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.os.Handler.dispatchMessage(Handler.java:99)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.os.Looper.loop(Looper.java:137)
07-01 12:42:17.530: E/AndroidRuntime(8286): at android.app.ActivityThread.main(ActivityThread.java:4507)
07-01 12:42:17.530: E/AndroidRuntime(8286): at java.lang.reflect.Method.invokeNative(Native Method)
07-01 12:42:17.530: E/AndroidRuntime(8286): at java.lang.reflect.Method.invoke(Method.java:511)
07-01 12:42:17.530: E/AndroidRuntime(8286): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:978)
07-01 12:42:17.530: E/AndroidRuntime(8286): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
07-01 12:42:17.530: E/AndroidRuntime(8286): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:2)
请将listView_
替换为tempView
。可能它应该工作
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
ListView tempView = listView_.getRefreshableView();
LayoutInflater inflater = (LayoutInflater) context_.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout listViewFooter = (LinearLayout) inflater.inflate(R.layout.contodeposito_tuoivincoli_tabella_vincoli_footer, **tempView**, false);
tempView.addFooterView(listViewFooter);
}
}, 3000);