第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

android下拉刷新的第三方庫(kù)簡(jiǎn)單使用

標(biāo)簽:
Android
1.下载

去github上面下载pulltorefresh这个library或者去我的网盘链接:http://pan.baidu.com/s/1brSfBw 密码:ob9t 下载这个zip包,然后解压,在你的项目中添加这个包里面的library,PulltorefreshListFragment,PullToRefreshViewPager 这样三个工程,当然你如果想看到示例代码也可以添加LauncherActivity这个工程,

2.示例代码

在示例代码中我们可以看到PullToRefreshListActivity中只有下拉刷新的效果,而PullToRefreshGridActivity中且有上拉刷新的效果,这样对比代码来看,在List里面我们需要在布局文件的添加 ptr:ptrMode="both"这样的一个属性,就是支持上拉和下拉刷星的属性,当然添加这个属性还要加入xmlns:ptr="http://schemas.android.com/apk/res-auto"添加这样的一个属性,这样就可以实现上拉和下拉刷新的效果了,不过如果你在List里面不对setOnRefreshListener做改变的话,上拉和下拉刷新的效果是一样的,那么,我们就来研究一下setOnRefreshListener,setOnRefreshListener参数里面有一个实现接口的方法,这个接口有两种,一种是new OnRefreshListener<ListView>()另一种是new OnRefreshListener2<ListView>()。要想实现 上拉和下拉刷新效果不一样就要使用第二种。并且要实现里面的

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

}
@Override
public void onPullUpToRefresh(
        PullToRefreshBase<ListView> refreshView) {
    new GetDataTask2().execute();

}

这两个方法。那么也要实现GetDataTask()和GetDataTask2()这两个类,表示上拉刷新更新的方式 和下拉刷新更新的方式。那么我就把整个代码附上来。小伙伴们看看吧。

package com.example.pulltorefreshtest;

import java.util.ArrayList;
import java.util.LinkedList;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2;

import android.os.AsyncTask;
import android.os.Bundle;
import android.R.integer;
import android.app.Activity;
import android.text.format.DateUtils;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity {
    private PullToRefreshListView mpullToRefreshListView;
    private ArrayAdapter<String>mArrayAdapter;
    private LinkedList mArrayList = new LinkedList<String>();;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mpullToRefreshListView = (PullToRefreshListView) findViewById(R.id.pull_refresh_list);

        mArrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_expandable_list_item_1, mArrayList);
        mpullToRefreshListView.setAdapter(mArrayAdapter);

        mpullToRefreshListView.setOnRefreshListener(new OnRefreshListener2<ListView>() {

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

            }

            @Override
            public void onPullUpToRefresh(
                    PullToRefreshBase<ListView> refreshView) {
                new GetDataTask2().execute();

            }
            /*@Override
            public void onRefresh(PullToRefreshBase<ListView> refreshView) {
                String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(),
                        DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);

                // Update the LastUpdatedLabel
                refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);

                // Do work to refresh the list here.
                new GetDataTask().execute();
            }*/
        });

    }

    private class GetDataTask extends AsyncTask<Void, Void, String []> {

        @Override
        protected String[] doInBackground(Void... params) {
            // Simulates a background job.

            return mStrings;
        }

        @Override
        protected void onPostExecute(String[] result) {
             mArrayList.addFirst(result[0]);
            mArrayAdapter.notifyDataSetChanged();

            // Call onRefreshComplete when the list has been refreshed.
            mpullToRefreshListView.onRefreshComplete();

            super.onPostExecute(result);
        }
    }

    private String[] mStrings = { "Abbaye de Belloc"};
    private class GetDataTask2 extends AsyncTask<Void, Void, String []> {

        @Override
        protected String[] doInBackground(Void... params) {
            // Simulates a background job.

            return mStrings2;
        }

        @Override
        protected void onPostExecute(String[] result) {
             mArrayList.addFirst(result[0]);
            mArrayAdapter.notifyDataSetChanged();

            // Call onRefreshComplete when the list has been refreshed.
            mpullToRefreshListView.onRefreshComplete();

            super.onPostExecute(result);
        }
    }

    private String[] mStrings2 = { "hahahha"};
}

布局文件为

<?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:orientation="vertical" >

<!--     The PullToRefreshListView replaces a standard ListView widget. -->

    <com.handmark.pulltorefresh.library.PullToRefreshListView
         xmlns:ptr="http://schemas.android.com/apk/res-auto"
        android:id="@+id/pull_refresh_list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:cacheColorHint="#00000000"
        android:divider="#19000000"
        android:dividerHeight="4dp"
        android:fadingEdge="none"
        android:fastScrollEnabled="false"
        android:footerDividersEnabled="false"
        android:headerDividersEnabled="false"
        android:smoothScrollbar="true"
        ptr:ptrMode="both"
        ptr:ptrDrawable="@drawable/lottery" 
        />

</LinearLayout>
點(diǎn)擊查看更多內(nèi)容
16人點(diǎn)贊

若覺(jué)得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
移動(dòng)開(kāi)發(fā)工程師
手記
粉絲
1
獲贊與收藏
129

關(guān)注作者,訂閱最新文章

閱讀免費(fèi)教程

感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專(zhuān)欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消