Back to project page doubanbook4android.
The source code is released under:
Eclipse Public License - v 1.0 THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECI...
If you think the Android project doubanbook4android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.study.doubanbook_for_android.activity; /*from w ww . j a va2s . co m*/ import java.util.ArrayList; import java.util.List; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.BaseAdapter; import android.widget.ListView; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; import com.handmark.pulltorefresh.library.PullToRefreshListView; import com.study.doubanbook_for_android.R; /** * * ??????????,fetchdata,sendMessage,seleHandleMsg,selfhandleMsg??BUG updatatime * 2013-12-13 * * @author tezuka-pc * * @param <T> */ public class BaseP2RActivity<T> extends BaseActivity implements OnRefreshListener<ListView>, OnItemClickListener { PullToRefreshListView p2r_lv; protected ArrayList<T> dataList = new ArrayList<T>(); public static final int REQUEST_CODE_PUBLISH = 0; protected BaseAdapter adapter; protected int pageIndex = 0; public static final int SUCCESS = 0; public static final int FAILURE = 1; // thread private MessageHandler msgHandler; class MessageHandler extends Handler { public MessageHandler(Looper looper) { super(looper); } @Override public void handleMessage(Message msg) { // ???????? ??????????????title? // result = (GeneralResult) (msg.obj); // addData(result.getBooks()); selfHandleMsg(msg); } } /** * ??MESSAGEHANDLER??????????UI?? * * @param b * @param status */ void sendMessage(Object b, int status) { Message message = Message.obtain(); message.arg1 = status; message.obj = b; msgHandler.sendMessage(message); } /** * ????????????????,?????????? * * @param msg */ public void selfHandleMsg(Message msg) { // TODO Auto-generated method stub } void initP2RLvAndThread() { // init p2r p2r_lv = (PullToRefreshListView) this.findViewById(R.id.p2r_lv); ListView listview = p2r_lv.getRefreshableView(); listview.setVerticalFadingEdgeEnabled(false); p2r_lv.setMode(Mode.PULL_FROM_END); p2r_lv.setShowIndicator(false); p2r_lv.setOnItemClickListener(this); p2r_lv.setOnRefreshListener(this); p2r_lv.setAdapter(getAdapter()); // init msgHandler Looper looper = Looper.myLooper(); msgHandler = new MessageHandler(looper); } /** * ?????? * * @param data */ void addData(List<T> data) { refreshCompleted(); if (data != null) { dataList.addAll(data); // TODO DEBUG?WHY // ???????????????????,??????????? // p2r_lv.setAdapter(adapter); adapter.notifyDataSetChanged(); } } // ????????? protected void reUpdateData() { dataList.clear(); fetchData(); } protected void refreshCompleted() { p2r_lv.onRefreshComplete(); } // ------------------------------------------------ /** * ?????????????. */ public void fetchData() { } @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { } @Override public void onRefresh(PullToRefreshBase<ListView> refreshView) { } // ??adatper???????? protected void notifyUpdate() { getAdapter().notifyDataSetChanged(); } private BaseAdapter getAdapter() { return adapter; } }