使用LinkedList。。。。LinkedList.addFirst(“helloworld”);
package com.example.helloworld;
import java.util.Arrays;
import java.util.LinkedList;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
public class MainActivity extends Activity {
private String[] mStrings = { "123", "1234", "12345"};
private PullToRefreshListView lV;
private ArrayAdapter<String> adapter;
private LinkedList<String> mListItems;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mListItems = new LinkedList<String>();
mListItems.addAll(Arrays.asList(mStrings));
lV = (PullToRefreshListView) findViewById(R.id.mylv);
adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1,mListItems);
lV.setAdapter(adapter);
lV.setOnRefreshListener(new OnRefreshListener<ListView>() {
@Override
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... arg0) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Void result) {
mListItems.addFirst("dajiahao");
adapter.notifyDataSetChanged();
lV.onRefreshComplete();
};
}.execute();
}
});
}
}
使用ArrayList。。。。arrayList.add(0,”helloworld”);
package com.example.helloworld;
import java.util.ArrayList;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class SecondActivity extends Activity {
private PullToRefreshListView myListView;
private ArrayList<String> arrayList;
private ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
arrayList = new ArrayList<String>();
arrayList.add("hello");
arrayList.add("hongye");
myListView = (PullToRefreshListView) findViewById(R.id.myListView);
adapter = new ArrayAdapter<String>(SecondActivity.this,
android.R.layout.simple_list_item_1, arrayList);
myListView.setAdapter(adapter);
myListView.setOnRefreshListener(new OnRefreshListener<ListView>() {
@Override
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... arg0) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
arrayList.add(0, "secondActivity");
adapter.notifyDataSetChanged();
myListView.onRefreshComplete();
super.onPostExecute(result);
}
}.execute();
}
});
}
}