qq_27665781 2015-08-18 12:34 采纳率: 100%
浏览 1654

求各位大神帮忙 急急急... 点击事件直接不执行了 告诉我怎么修改下

/*

  • 上拉加载
    */
    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);

    }

}

  • 写回答

1条回答 默认 最新

  • qq_27665781 2015-08-18 12:36
    关注

    The application may be doing too much work on its main thread. 一直报这个错误,然后点击事件进不去了

    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?