http://www.it165.net/pro/html/201410/24954.html
activity——xml
##导入library时不能导入的问题
library文件下缺少这两个文件在别的文件下拷贝。
#####关于PullToRefreshListView 和 getItemAtPosition
http://www.itstrike.cn/Question/736d7601-49bc-42e1-87a1-6cb664876e31.html
####区分上拉和下拉
http://www.tuicool.com/articles/ZfmiEj
refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);
if (refreshView.isShownHeader()) {
if (mList!=null) {
mList.clear();
}
getAllInformation(false, 0);
new GetDataTask().execute();
}
if (refreshView.isShownFooter()) {
getAllInformation(false, 2);
new GetDataTask().execute();
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long id) {
// TODO Auto-generated method stub
RuKuJcVo bean = (RuKuJcVo) arg0.getItemAtPosition(position);
Intent mintent = new Intent(getActivity(), RuKuDetailActivity.class);
mintent.putExtra("mainId", bean.getID());// id
mintent.putExtra("BusX", bean.getPym());// 车型
mintent.putExtra("BusH", bean.getLocono());// 车号
System.out.println("当前机车ID===" + bean.getID());
startActivity(mintent);
}
<!-- xmlns:ptr = "http://schemas.android.com/apk/res-auto" 为我们要使用PullToRefresh 里面一些属性需要引的命名空间 -->
<com.handmark.pulltorefresh.library.PullToRefreshListView
xmlns:ptr = "http://schemas.android.com/apk/res-auto"
android:id="@+id/pull_refresh_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="4dp"
android:fadingEdge="none"
android:fastScrollEnabled="false"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false"
android:smoothScrollbar="true"
ptr:ptrMode="both"
/>
Activity
public class MainActivity extends Activity {
private String[] mStrings = { "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi",
"Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre",
"Allgauer Emmentaler", "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi",
"Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre",
"Allgauer Emmentaler" };
private LinkedList<String> mListItems;
private PullToRefreshListView mPullRefreshListView;
private ArrayAdapter<String> mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPullRefreshListView = (PullToRefreshListView) findViewById(R.id.pull_refresh_list);
mPullRefreshListView.setOnRefreshListener(new OnRefreshListener<ListView>() {
@Override
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(),
DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);
// Update the LastUpdatedLabel
refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);
// Do work to refresh the list here.
new GetDataTask().execute();
}
});
mListItems = new LinkedList<String>();
mListItems.addAll(Arrays.asList(mStrings));
mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mListItems);
//这两个绑定方法用其一
// 方法一
// mPullRefreshListView.setAdapter(mAdapter);
//方法二
ListView actualListView = mPullRefreshListView.getRefreshableView();
actualListView.setAdapter(mAdapter);
}
private class GetDataTask extends AsyncTask<Void, Void, String> {
//后台处理部分
@Override
protected String doInBackground(Void... params) {
// Simulates a background job.
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
String str="Added after refresh...I add";
return str;
}
//这里是对刷新的响应,可以利用addFirst()和addLast()函数将新加的内容加到LISTView中
//根据AsyncTask的原理,onPostExecute里的result的值就是doInBackground()的返回值
@Override
protected void onPostExecute(String result) {
//在头部增加新添内容
mListItems.addFirst(result);
//通知程序数据集已经改变,如果不做通知,那么将不会刷新mListItems的集合
mAdapter.notifyDataSetChanged();
// Call onRefreshComplete when the list has been refreshed.
mPullRefreshListView.onRefreshComplete();
super.onPostExecute(result);
}
}
}