Android implements slide and slide events, while android implements slide events.
Those who have done development are certainly not unfamiliar with downloading, refreshing, and loading. Because we often use it, how can we achieve this effect? I believe many of my friends have helped me quickly achieve the above results through third-party components today, ensuring that every partner can get started quickly. First, I would like to share with you:
Decline Refresh:
Slide loading:
Third-party resources: https://github.com/maxwin-z/xlistview-android. after resources are downloaded, let's start with the Implementation:
We decompress the downloaded package and copy the following six files in the package to the project:
Our Activity:
Public class MainActivity 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; // the start position of the data: private static int refreshCnt = 0; // The number of times the private Date date is refreshed = new Date (); private SimpleDateFormat format = new SimpleDateFormat ("yyyy-MM-dd HH: Mm: ss "); // set the Update Time Format @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); geneItems (); mListView = (XListView) findViewById (R. id. xListView); mListView. setPullLoadEnable (true); // set the pull-down refresh // mListView. setPullLoadEnable (false); // you cannot attach more operations. // mListView. setPullRefreshEnable (false); // you cannot set mAdapter = new ArrayAdap to be refreshed. Ter <String> (this, R. layout. xlist_item, items); mListView. setAdapter (mAdapter); mListView. setRefreshTime (format. format (date); // set the Update Time To 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 (); date = new Date (); mListView. setRefreshTime (format. format (date); // set the update time} // returns the result of refreshing the log @ Override public void onRefresh () {mHandler. postDelayed (new Runnable () {@ Override public void run () {start = ++ refreshCnt; items. clear (); MainActivity. this. geneItems (); mAdapter. notifyDataSetChanged (); MainActivity. this. onLoad () ;}}, 2000) ;}// slide loading @ Override public void onLoadMore () {mHandler. postDelayed (new Runnable () {@ Override public void run () {MainActivity. this. geneItems (); mAdapter. notifyDataSetChanged (); MainActivity. this. onLoad () ;},2000 );}}
Action_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="#f0f0f0"> <me.maxwin.view.XListView android:id="@+id/xListView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:cacheColorHint="#00000000"> </me.maxwin.view.XListView></LinearLayout>
Okay, our project has been completed. You can perform the operation.