真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

PullToRefreshListView實(shí)現(xiàn)多條目加載上拉刷新和下拉加載

本文實(shí)例為大家分享了Android九宮格圖片展示的具體代碼,供大家參考,具體內(nèi)容如下

網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)建站!專注于網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、微信小程序開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了柳城免費(fèi)建站歡迎大家使用!

XML布局

主頁面main布局


pulllist布局


java代碼

App頁面

package com.example.duanpengpenglx20171108;

import android.app.Application;

import com.nostra13.universalimageloader.cache.memory.impl.UsingFreqLimitedMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;

/**
 * Created by 朋 on 2017/11/8.
 */

public class App extends Application {
  @Override
  public void onCreate() {
    super.onCreate();
    ImageLoaderConfiguration config = new ImageLoaderConfiguration
        .Builder(this)
        .memoryCacheExtraOptions(480,800)
        .threadPoolSize(5)
        .threadPriority(Thread.NORM_PRIORITY - 2)
        .denyCacheImageMultipleSizesInMemory()
        .memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) // You can pass your own memory cache implementation/你可以通過自己的內(nèi)存緩存實(shí)現(xiàn)
        .memoryCacheSize(2 * 1024 * 1024)
        .tasksProcessingOrder(QueueProcessingType.LIFO)
        .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
        .imageDownloader(new BaseImageDownloader(this, 5 * 1000, 30 * 1000)) // connectTimeout (5 s), readTimeout (30 s)超時時間
        .writeDebugLogs() // Remove for release app
        .build();//開始構(gòu)建
//初始化imageloader;
    ImageLoader.getInstance().init(config);
  }
}

MainActivity頁面

public class MainActivity extends AppCompatActivity {


  List arr = new ArrayList();
  private View view;
  private ListView lv;
  private Adapter adapter;
  int i = 0;
  private PullToRefreshListView pull;
  private Adapter adapter1;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    pull = (PullToRefreshListView) findViewById(R.id.pull);
    pull.setMode(PullToRefreshBase.Mode.BOTH);
    ListView lv = pull.getRefreshableView();
    adapter1 = new Adapter();
    lv.setAdapter(adapter1);

    new MyAsyncTask().execute("http://www.93.gov.cn/93app/data.do?channelId=0&startNum=0");
    pull.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2() {
      @Override
      //上拉
      public void onPullDownToRefresh(PullToRefreshBase refreshView) {
        arr.clear();
        i = 0;
        new MyAsyncTask().execute("http://www.93.gov.cn/93app/data.do?channelId=0&startNum=" + i);
      }
      @Override
      //下拉加載20條
      public void onPullUpToRefresh(PullToRefreshBase refreshView) {
        i = i + 20;new MyAsyncTask().execute("http://www.93.gov.cn/93app/data.do?channelId=0&startNum=" + i);

      }
    });
  }
  class MyAsyncTask extends AsyncTask {

    @Override
    protected String doInBackground(String... params) {
      String string = "";
      StringBuffer stringBuffer = new StringBuffer();
      try {
        URL url = new URL(params[0]);
        URLConnection urlConnection = url.openConnection();
        InputStream inputStream = urlConnection.getInputStream();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        while ((string = bufferedReader.readLine()) != null) {
          stringBuffer.append(string);
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
      return stringBuffer.toString();
    }

    @Override
    protected void onPostExecute(String s) {
      super.onPostExecute(s);
      Jbean fragone_bean = new Gson().fromJson(s, Jbean.class);
      List data = fragone_bean.getData();
      arr.addAll(data);
      adapter1.notifyDataSetChanged();
      pull.onRefreshComplete();
    }
  }

  class Adapter extends BaseAdapter {

    @Override
    public int getCount() {
      return arr.size();
    }

    @Override
    public Object getItem(int position) {
      return arr.get(position);
    }

    @Override
    public long getItemId(int position) {
      return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      Sj sj = new Sj();
      Jbean.DataBean dataBean = arr.get(position);
      if (convertView==null){
        convertView = View.inflate(MainActivity.this,R.layout.pulllist,null);
        sj.image=convertView.findViewById(R.id.iv);
        sj.tv=convertView.findViewById(R.id.tv);
        convertView.setTag(sj);
      }else {
        sj =(Sj) convertView.getTag();
      }
      sj.tv.setText(dataBean.getSUBTITLE());
      DisplayImageOptions options = new DisplayImageOptions.Builder()
          .cacheInMemory(true)
          .cacheOnDisk(true)
          .showImageOnLoading(R.drawable.zhengzaijiazai)
          .showImageForEmptyUri(R.drawable.zhengzaijiazai)
          .showImageOnFail(R.drawable.zhengzaijiazai)
          .bitmapConfig(Bitmap.Config.RGB_565)
          .build();
      ImageLoader.getInstance().displayImage((String) dataBean.getIMAGEURL(),sj.image,options);

      return convertView;
    }
  }
  class Sj{
    ImageView image;
    TextView tv;
  }
  }

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。


本文名稱:PullToRefreshListView實(shí)現(xiàn)多條目加載上拉刷新和下拉加載
分享URL:http://weahome.cn/article/ggipcp.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部