Everyone must have been aware of Taobao Ah Tmall some shopping website merchandise drop-down refresh info pull-up load item details
See Effect
Here we use the Xlistview package to copy some configuration code to implement these functions
First of all prepare to have Xlistview package we create a project such as demos and then put the Java file under the Me.maxwei.view package R path to your package path.
after the ListView of Main in XML is OK
Next, we'll look at the code for the main mainactivity.
Note that the two methods of implementing implements Ixlistviewlistener look at the code
Package Com.example.demos;
Import java.util.ArrayList;
Import java.util.List;
Import Me.maxwin.view.XListView;
Import Me.maxwin.view.XListView.IXListViewListener;
Import Android.os.Bundle;
Import Android.os.Handler;
Import android.app.Activity;
Import Android.view.Menu;
Import Android.widget.ArrayAdapter;
Import Android.widget.Toast;
public class Mainactivity extends Activity implements Ixlistviewlistener {
Private Xlistview LV;
Private arrayadapter<string> adapter;
Private Handler hand;
Private list<string> li= new arraylist<string> ();
private int num = 18;//Set initial data with 18 bars
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Loading data
GetData ();
Listview
LV = (Xlistview) Findviewbyid (r.id.lv);
Configuration information
Lv.setpullloadenable (TRUE);//support pull-down to load data
Lv.setpullrefreshenable (TRUE);//support pull up Refresh data
Lv.setxlistviewlistener (this);//support triggering of various events
Set Adapter
adapter = new Arrayadapter<string> (this, R.layout.list_item, Li);
Lv.setadapter (adapter);
Used to use thread time
Hand = new Handler ();
}
/**
* Initialization data and subsequent pull-down loading data into the collection
*/
private void GetData () {
TODO auto-generated Method Stub
for (int i = 0; i < num; i++) {
Li.add ("Hellow fanaw!" + i);
}
}
Refresh
@Override
public void Onrefresh () {
Start thread
Hand.postdelayed (New Runnable () {
@Override
public void Run () {
Can do refresh processing
}
}, 2000);
Lv.stoprefresh ();//Stop Refresh
Toast.maketext (This, "refresh completed", 0). Show ();
}
Load
@Override
public void Onloadmore () {
Start thread
Hand.postdelayed (New Runnable () {
@Override
public void Run () {
Do some loading operations
num + = 10;
GetData ();
Adapter.notifydatasetchanged ();
}
}, 2000);
Lv.stoploadmore ();//Stop loading
Toast.maketext (This, "li.lenth==" + li.size (), 0). Show ();
}
}