国产午夜精品理论片,国产亚洲精品久久久999蜜臀,国产精品久久久久久久久免费,国产卡一卡二卡3卡4乱码,国产精品午夜无码av天美传媒

Andorid5.0原生下拉刷新簡單實(shí)現(xiàn)
發(fā)布時(shí)間:2016/1/15 來源:搜數(shù)網(wǎng)絡(luò) 瀏覽:20

這個(gè)出來也有些日子了,相對于上一個(gè)19.1.0版本中的橫條效果好看了很多。使用起來也很簡單。 
這里寫圖片描述

"http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:ignore="MergeRootFrame" >

    .support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        "@+id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
        
    .support.v4.widget.SwipeRefreshLayout>

package hi.xiaoyu.swiperefreshlayout;

import hi.xiaoyu.swiperefreshlayout.adapter.TestAdapter;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
import android.widget.ListView;

public class MainActivity extends Activity implements OnRefreshListener {

    private SwipeRefreshLayout swipeLayout;
    private ListView listView;
    private List listDatas;
    private TestAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
        listView = (ListView) findViewById(R.id.list);
        swipeLayout.setOnRefreshListener(this);
        swipeLayout.setColorSchemeResources(android.R.color.holo_orange_dark,
                android.R.color.holo_green_light,
                android.R.color.holo_orange_light,
                android.R.color.holo_red_light);
        listDatas = new ArrayList();
        for (int i = 0; i < 10; i++) {
            listDatas.add("item" + i);
        }
        adapter = new TestAdapter(this, listDatas, R.layout.test_item);
        listView.setAdapter(adapter);
    }

    public void onRefresh() {
        new Handler().postDelayed(new Runnable() {
            public void run() {
                swipeLayout.setRefreshing(false);
                listDatas.addAll(listDatas);
                adapter.notifyDataSetChanged();
            }
        }, 3000);
    }

}

幾行代碼就可以實(shí)現(xiàn)下拉刷新,效果也還不錯(cuò),不用引入第三方j(luò)ar,唯一的缺憾就是沒有上拉加載,不知道谷歌工程師基于什么方面的考慮,希望能在下個(gè)版本看到。不過自己修改下源碼加一個(gè)上拉也比較簡單,結(jié)合上個(gè)一個(gè)版本的刷新效果做成上拉效果還不錯(cuò),有時(shí)間再補(bǔ)上。 

 

返回