我有两个textviews和一个浮动操作按钮,以及一个listview。
目前,我可以将swiperefreshlayout用于listview,但希望它用于整个视图,即,当我从活动顶部向下滑动时,listview应该在后台更新。
谁能帮我。
这是我当前的xml文件。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/view_tickets_activity_text_view_note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp" />
<TextView android:id="@+id/view_tickets_activity_text_view_customer_name"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/view_tickets_activity_text_view_note"
android:layout_below="@+id/view_tickets_activity_text_view_note"
android:layout_marginTop="10dp" />
<android.support.design.widget.FloatingActionButton android:id="@+id/view_tickets_activity_floating_btn_add_ticket"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignTop="@+id/view_tickets_activity_text_view_customer_name" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/view_tickets_activity_floating_btn_add_ticket"
android:layout_marginTop="15dp">
<ListView
android:id="@+id/view_tickets_activity_list_view_tickets"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
最佳答案
在整个布局上使用SwipeRefreshLayout
:
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe"
android:layout_height="match_parent"
android:layout_width="match_parent">
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<TextView
android:id="@+id/view_tickets_activity_text_view_note"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content" />
<TextView
android:id="@+id/view_tickets_activity_text_view_customer_name"
android:layout_alignLeft="@+id/view_tickets_activity_text_view_note"
android:layout_below="@+id/view_tickets_activity_text_view_note"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_width="220dp" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/view_tickets_activity_floating_btn_add_ticket"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/view_tickets_activity_text_view_customer_name"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
<ListView
android:id="@+id/view_tickets_activity_list_view_tickets"
android:layout_below="@+id/view_tickets_activity_floating_btn_add_ticket"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_width="match_parent" />
</RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>
并在中更新您的
ListView
: @Override
public void onRefresh() {
// Update Adapter for ListView here
adapter.notifyDataSetChanged();
}