Android中頁面添加計時器進行的重新整理

來源:互聯網
上載者:User

標籤:style   class   pad   set   cat   tor   ace   cep   auto   

1.對原生的SwipeRefreshLayout 進行自訂 

public class AutoSwipeRefreshLayout extends SwipeRefreshLayout {
public AutoSwipeRefreshLayout(Context context) {
super(context);
}

public AutoSwipeRefreshLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}

/**
* 自動重新整理
*/
public void autoRefresh() {
try {
Field mCircleView = SwipeRefreshLayout.class.getDeclaredField("mCircleView");
mCircleView.setAccessible(true);
View progress = (View) mCircleView.get(this);
progress.setVisibility(VISIBLE);

Method setRefreshing = SwipeRefreshLayout.class.getDeclaredMethod("setRefreshing", boolean.class, boolean.class);
setRefreshing.setAccessible(true);
setRefreshing.invoke(this, true, true);
} catch (Exception e) {
e.printStackTrace();
}
}
}

2.使用時直接調用autoRefresh()方法可以進行自動重新整理
3.需要添加正在重新整理或者正在載入的提示的情況: 可以再布局中,添加Textview實現
xml檔案如下
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:id="@+id/tv_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="@dimen/dp_5" />

<com.shzx.zcyg.customview.AutoSwipeRefreshLayout
android:id="@+id/refresh_list"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:id="@+id/tv_no_content"
style="@style/title_second_setting"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:layout_marginTop="@dimen/dp_20"
android:text="@string/no_content"
android:visibility="gone" />

<android.support.v7.widget.RecyclerView
android:id="@+id/lv_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</RelativeLayout>

</com.shzx.zcyg.customview.AutoSwipeRefreshLayout>


</LinearLayout>

4.實現代碼:
refreshsetOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
tv_loading.setText(R.string.data_loading);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// 添加需要重新整理的資料
          getdata();
refresh_order.setRefreshing(false);
if (total_page==0){
tv_loading.setVisibility(View.GONE);
tv_no_content.setVisibility(View.VISIBLE);
}
}
}, 3000);
}
});

Android中頁面添加計時器進行的重新整理

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.