Android Open Source - XListView-Android X List View Activity






From Project

Back to project page XListView-Android.

License

The source code is released under:

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, includi...

If you think the Android project XListView-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package me.maxwin;
/*from w  ww  .  ja  v  a2 s. c o m*/
import java.util.ArrayList;

import me.maxwin.view.XListView;
import me.maxwin.view.XListView.IXListViewListener;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ArrayAdapter;

public class XListViewActivity extends Activity implements IXListViewListener {
  private XListView mListView;
  private ArrayAdapter<String> mAdapter;
  private ArrayList<String> items = new ArrayList<String>();
  private Handler mHandler;
  private int start = 0;
  private static int refreshCnt = 0;
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    geneItems();
    mListView = (XListView) findViewById(R.id.xListView);
    mListView.setPullLoadEnable(true);
    mAdapter = new ArrayAdapter<String>(this, R.layout.list_item, items);
    mListView.setAdapter(mAdapter);
//    mListView.setPullLoadEnable(false);
//    mListView.setPullRefreshEnable(false);
    mListView.setXListViewListener(this);
    mHandler = new Handler();
  }

  private void geneItems() {
    for (int i = 0; i != 20; ++i) {
      items.add("refresh cnt " + (++start));
    }
  }

  private void onLoad() {
    mListView.stopRefresh();
    mListView.stopLoadMore();
    mListView.setRefreshTime("??");
  }
  
  @Override
  public void onRefresh() {
    mHandler.postDelayed(new Runnable() {
      @Override
      public void run() {
        start = ++refreshCnt;
        items.clear();
        geneItems();
        // mAdapter.notifyDataSetChanged();
        mAdapter = new ArrayAdapter<String>(XListViewActivity.this, R.layout.list_item, items);
        mListView.setAdapter(mAdapter);
        onLoad();
      }
    }, 2000);
  }

  @Override
  public void onLoadMore() {
    mHandler.postDelayed(new Runnable() {
      @Override
      public void run() {
        geneItems();
        mAdapter.notifyDataSetChanged();
        onLoad();
      }
    }, 2000);
  }

}




Java Source Code List

me.maxwin.XListViewActivity.java
me.maxwin.view.XListViewFooter.java
me.maxwin.view.XListViewHeader.java
me.maxwin.view.XListView.java