【问题标题】:Chris Banes Pull To Refresh ListView/GridView in FragmentChris Banes 在 Fragment 中拉取刷新 ListView/GridView
【发布时间】:2012-07-13 20:40:08
【问题描述】:

我正在尝试在片段中包含 Chris Banes Pull 以刷新实现,并且在创建 PullToRefreshListView 时出现以下错误:

java.lang.NoSuchFieldError: com.handmark.pulltorefresh.library.R$id.pull_to_refresh_text

PullToRefreshListView的创建点是在继承ListFragment的类中的onCreateView:

public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {

    ViewGroup viewGroup = (ViewGroup) super.onCreateView(inflater, container, savedInstanceState);

    View lvOld = viewGroup.findViewById(android.R.id.list);

    listView = new PullToRefreshListView(getActivity());
    listView.setId(android.R.id.list);
    listView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
    listView.setDrawSelectorOnTop(false);
    adapter = new LazyAdapter(getActivity());
    listView.setAdapter(adapter);

    FrameLayout parent = (FrameLayout) lvOld.getParent();

    parent.removeView(lvOld);
    lvOld.setVisibility(View.GONE);

    parent.addView(listView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));

    return viewGroup;

}

布局是这样的:

<?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="#FF0000">

    <ListView
        android:id="@+id/android:list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    />

</LinearLayout>

我错过了什么?

【问题讨论】:

    标签: android listview fragment pull-to-refresh


    【解决方案1】:

    更换“拉动刷新”小部件http://markupartist.comfrom Johan Nilsson 后,我遇到了同样的错误。有必要从布局目录中删除 header.xml(包含对错误消息中提到的文本的引用)。文本已经是 Chris Banes 图书馆的一部分。

    【讨论】:

    • 非常感谢!我引用了两个库并且布局名称相同,这似乎是一个问题。我删除了对 Johan Nilsson 的图书馆的参考,现在正在工作:)
    猜你喜欢
    • 2023-03-25
    • 1970-01-01
    • 2016-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多