xml中:
1 <包名.XListView 2 android:id="@+id/peopleNearby_listView" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent"> 5 6 </包名.XListView>
Java代码中:
1 初始化中: 2 mXListView.setPullLoadEnable(true); 3 mXListView.setXListViewListener(this);//本类要实现implements IXListViewListener接口 5 6 if (pageNum > 1) { 7 mXListView.setStackFromBottom(true); 8 } else { 9 mXListView.setStackFromBottom(false); 10 } 11 12 13 @SuppressLint("HandlerLeak") 14 private void initViewLVDataToDisplay() { 15 final Handler handle = new Handler() { 16 public void handleMessage(Message msg) { 17 if (msg.what == 1) { 18 pageOld = pageNum; 19 setDataLV(); 20 Toast.makeText(PeopleNearbyActivity.this, "访问网络成功", 21 Toast.LENGTH_SHORT).show(); 22 } else { 23 Toast.makeText(PeopleNearbyActivity.this, "访问网络失败", 24 Toast.LENGTH_SHORT).show(); 25 } 26 onLoad(); 27 } 28 }; 29 30 final NoButtonDialog myDialog = new NoButtonDialog( 31 PeopleNearbyActivity.this, R.style.MyDialog); 32 myDialog.show(); 33 // 设置ProgressDialog 是否可以按退回键取消 34 myDialog.setCancelable(false); 35 new Thread() { 36 public void run() { 37 Message msg = Message.obtain(); 38 msg.what = 0; 39 try { 40 41 Looper.prepare(); 42 String url = https.url86; 43 List<NameValuePair> params = new ArrayList<NameValuePair>(); 44 params.add(new BasicNameValuePair("uid", SharedPClass.getParam("uid", PeopleActivity.this))); 45 params.add(new BasicNameValuePair("longitude", String.valueOf(longitude))); 46 params.add(new BasicNameValuePair("latitude", String.valueOf(latitude))); 47 params.add(new BasicNameValuePair("page", pageNum + "")); 48 String str; 49 http.getHttpClient(); 50 str = http.doPost(url, params, PeopleActivity.this); 51 System.out.println(url + " " + params.toString()); 52 System.out.println(url + " 对应的返回json数据 " + str); 53 54 JSONObject json = new JSONObject(str); 55 if (Integer.valueOf(json.getString("status")) == 1) { 56 // 验证成功 57 msg.what = 1; 58 // 解析json数据,然后设置在mMatchInfoData变量中 59 boolean flag = parserDataAndSetList(str); 60 if (flag == false) { 61 msg.what = 0; 62 } 63 } 64 } catch (Exception e) { 65 // TODO: handle exception 66 } finally { 67 myDialog.dismiss(); 68 } 69 handle.sendMessage(msg); 70 Looper.loop(); 71 }; 72 }.start(); 73 }
1 @Override 2 public void onRefresh() { 3 // TODO Auto-generated method stub 4 pageOld = 0; 5 pageNum = 1; 6 initViewLVDataToDisplay(); 7 } 8 9 @Override 10 public void onLoadMore() { 11 // TODO Auto-generated method stub 12 //pageNum = allListData.size() / sendNumOneTime + 1; 13 if (pageNum == pageOld) { 14 pageNum++; 15 //结束加载功能,回复界面 16 onLoad(); 17 }else { 18 initViewLVDataToDisplay(); 19 } 20 } 21 22 private void onLoad() { 23 try { 24 mXListView.setRefreshTime("刚刚"); 25 mXListView.stopRefresh(); 26 mXListView.stopLoadMore(); 27 } catch (Exception e) { 28 // TODO Auto-generated catch block 29 e.printStackTrace(); 30 Log.i("qianhailixiangtesterror", "onLoad报错inTender"); 31 } 32 }