我在我的ListFragment上使用Chris Banes ActionBar-PullToRefresh。
除ListView为空外,一切正常。当ListView为空(并且空文本可见)时,拉动刷新功能不起作用,尽管我在getListView().getEmptyView()
中设置了theseChildrenArePullable()
。
我也试过了allChildrenArePullable()
但没有效果。
我的 ListFragment :
中的代码@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
listAdapter = new ListsAdapter(getActivity(), items);
setListAdapter(listAdapter);
Cursor cursor = ListProvider.getInstance().selectAll();
ArrayList<BaseModel> cursorItems = ListProvider.getInstance().rowsToArrayList(cursor);
for(BaseModel cursorItem : cursorItems) {
items.add((ListModel) cursorItem);
}
}
public void onActivityCreated(Bundle savedState) {
super.onActivityCreated(savedState);
registerForContextMenu(getListView());
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.adapter_lists, container, false);
return layout;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getListView().setOnItemLongClickListener(this);
mPullToRefreshLayout = new PullToRefreshLayout(getActivity());
ActionBarPullToRefresh.from(getActivity())
.insertLayoutInto((ViewGroup) view)
.theseChildrenArePullable(getListView(), getListView().getEmptyView())
.listener(this)
.setup(mPullToRefreshLayout);
}
我的 adapter_lists .xml:
中的代码<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>
<TextView android:id="@id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="@string/message_my_lists_empty"/>
</LinearLayout>
答案 0 :(得分:1)
所以我通过使用原生的SwipeRefreshLayout来解决这个问题。
要实现这一目标,您需要提供自己的观点:
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="@string/hello_world"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"/>
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
onViewCreated函数中的一些代码:
swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
swipeLayout.setOnRefreshListener(this);
swipeLayout.setColorScheme(
android.R.color.holo_blue_bright,
android.R.color.holo_green_light,
android.R.color.holo_orange_light,
android.R.color.holo_red_light);