編輯:Android開發實例
實例核心代碼:
package com.stay.main;
import java.net.HttpURLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONObject;
import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.stay.wifi.R;
/**
* @author Stay
* 動態加載listview數據,上拉 刷新,下拉 更多
*/
public class ListViewActivity extends Activity implements OnScrollListener {
private static final int LOAD = 0;
private static final int ERROR = 0;
private static final int MEMBER = 1;
private static final int LOADED = 2;
private static final int DIALOG = 3;
private static final int FULL = 4;
private NearbyAdapter adapter;
private ListView nearby_lv;
private RelativeLayout nearby_lv_header;
private Button list_bottom_btn;
private LinearLayout list_bottom_linear;
private TextView bottom_progress_text;
private RelativeLayout nearby_lv_footer;
private Button list_header_btn;
private LinearLayout list_header_linear;
private TextView heard_progress_text;
private ArrayList<JSONObject> nearby_data = new ArrayList<JSONObject>();
private int lastItem;
private HashMap<String, Drawable> imageCache;
private com.stay.main.ListViewActivity.MyHandler myHandler;
private ProgressDialog dialog;
private int curPage = 1;
private boolean isMember = false;
private int firstItem;
public int count;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initView();
myHandler.sendEmptyMessage(LOAD);
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
DebugUtil.debug("onScrollStateChanged");
//當滾動停止且滾動的總數等於數據的總數,去加載
if (lastItem == count && scrollState == SCROLL_STATE_IDLE) {
DebugUtil.debug("onScrollStateChanged--------next");
if (curPage == 4 && !isMember) {
DebugUtil.show(this, "您不是正式會員,請申請正式會員,");
list_bottom_linear.setVisibility(View.GONE);
} else {
//加載數據
myHandler.sendEmptyMessage(LOAD);
}
return;
}
//當往上拉時更新數據,將data清空然後去重新加載
if (firstItem == 0 && scrollState == SCROLL_STATE_IDLE) {
DebugUtil.debug("onScrollStateChanged--------refresh");
curPage = 0;
myHandler.sendEmptyMessage(LOAD);
}
}
本文實例講述了Android實現仿通訊錄側邊欄滑動SiderBar效果代碼。分享給大家供大家參考,具體如下: 之前看到某些應用的側邊欄做得不錯,想想自己也弄一個出
Android應用程序可以在許多不同地區的許多設備上運行。為了使應用程序更具交互性,應用程序應該處理以適合應用程序將要使用的語言環境方面的文字,數字,文件等。在本章中,我
本文實例講述了Android編程實現讀取手機聯系人、撥號、發送短信及長按菜單操作方法。分享給大家供大家參考,具體如下: 1.Andrid項目結構圖↓主要操作圖中紅
JSON代表JavaScript對象符號。它是一個獨立的數據交換格式,是XML的最佳替代品。本章介紹了如何解析JSON文件,並從中提取所需的信息。Android提供了四個