问题描述
- 求各位大神帮忙 急急急... 点击事件直接不执行了 告诉我怎么修改下
-
/*- 上拉加载
*/
public class queren extends Activity implements IXListViewListener{
public Context context;
public TelephonyManager telephonyManager;
public String deviceId;
private static String url ="http://www.yicaxie.cn:8918/xxdj/mobile/courierAppService";
public List list;
private XListView mListView;
List> data;
//分页参数开始
private int starter=0; //一开始
private int ender=20; //每页条数
JSONObject commonJson;
private String refreshCnt="0";
private String init = "0";
String a;private Handler mHandler;
SimpleAdapter simpleAdapterer;
private SimpleDateFormat mDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
HashMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.queren);
try {
orderList() ;
mListView = (XListView) findViewById(R.id.querenlistview);
mListView.setPullLoadEnable(true);
simpleAdapterer =new SimpleAdapter(queren.this, data, R.layout.item, new String[]{"orderId","orderState","userName","phoneNumber","orderDate","address","orderTotal","payType","shoesInfo"}, new int[]{R.id.orderId,R.id.orderstate,R.id.userName,R.id.phoneNumber,R.id.orderDate,R.id.address,R.id.orderTotal,R.id.payType,R.id.shoesInfo});
mListView.setAdapter(simpleAdapterer);
mListView.setXListViewListener(this);
mHandler = new Handler();
} catch (Exception e) {
e.printStackTrace();
}
}
//下拉
private void geneItems() {
starter =0;
ender =20;
refreshCnt="0";
init = "0";
}
//上啦
private void getItems() {
starter =starter+20;
ender =20;
init = "1";
refreshCnt=a;
}private String formatDateTime(long time) {
if (0 == time) {
return "";
}return mDateFormat.format(new Date(time));
}
/*
- 显示时间
*/
private void onLoad() {
mListView.stopRefresh();
mListView.stopLoadMore();
String text = formatDateTime(System.currentTimeMillis());
mListView.setRefreshTime(text);
}
public void orderList() throws Exception
{
/*
* 获取玩设备号
*/
telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
deviceId = "" + telephonyManager.getDeviceId();
//创建实体类对象
OrderType ordertype =new OrderType();
PhoneState phoneState =new PhoneState();
// HttpPost连接对象
HttpPost httpRequest = new HttpPost(url);
// 使用NameValuePair来保存要传递的Post参数
List params = new ArrayList();
// 添加调用方法参数
params.add(new BasicNameValuePair("action", "getOrderList"));
//添加公用参数
commonJson = new JSONObject();
commonJson.put("loginId",phoneState.getLoginId());
commonJson.put("loginKey",phoneState.getLoginKey());
commonJson.put("deviceId",deviceId);
commonJson.put("version",phoneState.getVersion());
commonJson.put("deviceType",phoneState.getDeviceType() );
params.add(new BasicNameValuePair("commonParams", commonJson.toString()));
//添加业务参数
JSONObject paramJson = new JSONObject();
paramJson.put("type", ordertype.getType());
paramJson.put("courierId", ordertype.getCourierId());
paramJson.put("start",starter );
paramJson.put("end",ender );
paramJson.put("queryId",refreshCnt );
params.add(new BasicNameValuePair("params", paramJson.toString()));
try
{
//设置字符集
HttpEntity httpentity = new UrlEncodedFormEntity(params, HTTP.UTF_8);
//请求httpRequest
httpRequest.setEntity(httpentity);
//取得默认的HttpClient
HttpClient httpclient = new DefaultHttpClient();
//取得HttpResponse
HttpResponse httpResponse = httpclient.execute(httpRequest);
//HttpStatus.SC_OK表示连接成功
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
//取得返回的字符串
String strResult = EntityUtils.toString(httpResponse.getEntity());
RspVO rspVO = GsonUnit.getObject(strResult, RspVO.class);
if(rspVO.getCode().equals("0")){
String rtnValue = rspVO.getRtnValues();
list = new Gson().fromJson(rtnValue, new TypeToken>(){}.getType());
if(list!=null&&list.size()>0)
{
data = new ArrayList>();
for (int i = 0; i < list.size(); i++) {
map = new HashMap();
map.put("id", list.get(i).getId());
map.put("orderId", list.get(i).getOrderId());
map.put("orderState", list.get(i).getOrderState());
map.put("userName", list.get(i).getUserName());
map.put("phoneNumber", list.get(i).getPhoneNumber());
map.put("orderDate", list.get(i).getOrderDate());
map.put("address", list.get(i).getAddress());
map.put("orderTotal", list.get(i).getOrderTotal());
map.put("payType", list.get(i).getPayType());
map.put("shoesInfo", list.get(i).getShoesInfo());
data.add(map);
}
if(init.equals("0")){
a =list.get(0).getId();
}
simpleAdapterer =new SimpleAdapter(queren.this, data, R.layout.item, new String[]{"orderId","orderState","userName","phoneNumber","orderDate","address","orderTotal","payType","shoesInfo"}, new int[]{R.id.orderId,R.id.orderstate,R.id.userName,R.id.phoneNumber,R.id.orderDate,R.id.address,R.id.orderTotal,R.id.payType,R.id.shoesInfo});
mListView.setAdapter(simpleAdapterer);//列表点击事件 mListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapoter, View view, int position, long ids) { HttpPost httpRequest = new HttpPost(url); List<NameValuePair> params = new ArrayList<NameValuePair>(); // 添加调用方法参数 params.add(new BasicNameValuePair("action", "getOrderList")); // 添加公有参数 params.add(new BasicNameValuePair("commonParams", commonJson.toString())); //添加私有参数 JSONObject paramJson = new JSONObject(); try { paramJson.put("id", list.get(position).getId()); } catch (JSONException e2) { e2.printStackTrace(); } params.add(new BasicNameValuePair("params", paramJson.toString())); try { //设置字符集 HttpEntity httpentity = new UrlEncodedFormEntity(params, HTTP.UTF_8); //请求httpRequest httpRequest.setEntity(httpentity); //取得默认的HttpClient HttpClient httpclient = new DefaultHttpClient(); //取得HttpResponse HttpResponse httpResponse = httpclient.execute(httpRequest); //HttpStatus.SC_OK表示连接成功 if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { //取得返回的字符串 String strResult = EntityUtils.toString(httpResponse.getEntity()); RspVO rspVO = GsonUnit.getObject(strResult, RspVO.class); if(rspVO.getCode().equals("0")){ String rtnValue = rspVO.getRtnValues(); Intent intent =new Intent(queren.this,querenmore.class); intent.putExtra("rtnValue", rtnValue); startActivityForResult(intent, 0); finish(); } } } catch (ClientProtocolException e) { e.printStackTrace(); System.out.println(e); } catch (IOException e) { e.printStackTrace(); System.out.println(e); } catch (Exception e) { e.printStackTrace(); System.out.println(e); } } }); } else{ Toast.makeText(queren.this, "没有更多数据", Toast.LENGTH_SHORT).show(); } if(list.size()<20) { Toast.makeText(context, "没有更多数据", Toast.LENGTH_SHORT).show(); } }else { Toast.makeText(queren.this, "服务器无相应", Toast.LENGTH_SHORT).show(); } } else { } } catch (ClientProtocolException e) { e.printStackTrace(); System.out.println(e); } catch (IOException e) { e.printStackTrace(); System.out.println(e); } catch (Exception e) { e.printStackTrace(); System.out.println(e); }
}
/*
- 下拉
- @see com.exaple.view.XListView.IXListViewListener#onRefresh()
*/
@Override
public void onRefresh() {
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
data.clear();
geneItems();try { orderList(); } catch (Exception e) { e.printStackTrace(); } onLoad(); //显示时间 }
}, 2000);
}
/* - 上拉
- @see com.exaple.view.XListView.IXListViewListener#onLoadMore()
*/
@Override
public void onLoadMore() {
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
getItems(); //调用上拉改变值
try {
orderList();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
simpleAdapterer.notifyDataSetChanged();
onLoad();
}
}, 2000);
}
- 显示时间
}
- 上拉加载
解决方案
The application may be doing too much work on its main thread. 一直报这个错误,然后点击事件进不去了
解决方案二:
求大神帮忙,急!!