PullToRefreshScrollView 的使用问题

innoyang 2016-07-27 04:33:36
RT 做了一个ScrollView 想加上下拉刷新。 找了一个例子 放到工程里,原来的activty是可以工作的。
但是我的是个Fragment,不太清楚如何使用 试了几次都不行java onCreateView代码如下:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_homepage, container, false);
initAdData();

mPullScrollView = new PullToRefreshScrollView(getActivity());
getActivity().setContentView(mPullScrollView);

mPullScrollView.setOnRefreshListener(new OnRefreshListener<ScrollView>() {

@Override
public void onPullDownToRefresh(PullToRefreshBase<ScrollView> refreshView) {
new GetDataTask().execute();
}

@Override
public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) {

}
});

mScrollView = mPullScrollView.getRefreshableView();
mScrollView.addView(rootView);

setLastUpdateTime();

return mPullScrollView;
}


layout如下:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bilibg"
android:clickable="true"
android:orientation="vertical"
android:scrollbars="vertical" >

<include layout="@layout/banner" />
。。。。。。。。
</LinearLayout>


</ScrollView>


报的错误是:java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
...全文
201 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
TyroLJS 2016-07-28
  • 打赏
  • 举报
回复
PullToRefreshScrollView既然使用这个了,为什么还要在布局里用ScrollView,不直接布局PullToRefreshScrollView呢,你的动态添加有必要么
innoyang 2016-07-28
  • 打赏
  • 举报
回复
引用 1 楼 cai784921129 的回复:
你写的好乱,你的pulltoReflesh已经有父容器了,
是有点乱 已经解决了 直接在layout里边加空间标签了
IT小蔡 2016-07-27
  • 打赏
  • 举报
回复
你写的好乱,你的pulltoReflesh已经有父容器了,

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧