コード例 #1
0
  public void openAutoLoad() {

    /*timer=new Timer();
    final GsonServlet<GetChatRecordReq, GetChatRecordRes> gServlet=new GsonServlet<GetChatRecordReq, GetChatRecordRes>(mContext);
    timer.schedule(new TimerTask() {

    	@Override
    	public void run() {

    		fillData(gServlet);
    		Log.d("dd","hello world!");
    	}
    }, 1000,5000);*/
    task = new HttpTask<GetChatRecordReq, GetChatRecordRes>(mContext);
    GetChatRecordReq req = new GetChatRecordReq();
    req.setDoctor_id(doctor_id);
    req.setPatient_id_card(patient_id);
    task.start(req, GetChatRecordRes.class);
    task.setOnResponseListening(
        new OnResponseListening<GetChatRecordReq, GetChatRecordRes>() {

          public void onResponseSuccess(GetChatRecordRes commonRes) {
            if (commonRes != null) {
              HashMap<String, ChatContent> doctor_content = commonRes.getDoctor_content();
              List<PatientChatContent> patient_content = commonRes.getPatient_content();
              if (patient_content.size() > 0) {
                String chatId = patient_content.get(patient_content.size() - 1).getChatId();
                int mSize = doctor_content.size();
                // 新的消息过来
                if (!lastContentId.equals(chatId) || size != mSize) {
                  if (adapter == null) {

                    adapter = new ChatAdapter(mContext, patient_content, doctor_content);
                    chat_record_list.setAdapter(adapter);
                  } else {
                    adapter.updateData(patient_content, doctor_content);
                  }
                  // chat_record_list.setAdapter(adapter);
                  chat_record_list.setSelection(patient_content.size() - 1);
                  size = mSize;
                  lastContentId = chatId;
                }
              }
            }
          }
        });
  }
コード例 #2
0
  public void fillData(GsonServlet<GetChatRecordReq, GetChatRecordRes> gServlet) {
    GetChatRecordReq req = new GetChatRecordReq();
    req.setDoctor_id(doctor_id);
    req.setPatient_id_card(patient_id);
    //	gServlet=new GsonServlet<GetChatRecordReq, GetChatRecordRes>(mContext);
    gServlet.request(req, GetChatRecordRes.class);
    gServlet.setOnResponseEndListening(
        new OnResponseEndListening<GetChatRecordReq, GetChatRecordRes>() {

          @Override
          public void onResponseEnd(
              GetChatRecordReq commonReq,
              GetChatRecordRes commonRes,
              boolean result,
              String errmsg,
              int responseCode) {
            // TODO Auto-generated method stub

          }

          @Override
          public void onResponseEndSuccess(
              GetChatRecordReq commonReq,
              GetChatRecordRes commonRes,
              String errmsg,
              int responseCode) {
            // TODO Auto-generated method stub
            if (commonRes != null) {
              HashMap<String, ChatContent> doctor_content = commonRes.getDoctor_content();
              List<PatientChatContent> patient_content = commonRes.getPatient_content();
              if (patient_content.size() > 0) {
                String chatId = patient_content.get(patient_content.size() - 1).getChatId();
                int mSize = doctor_content.size();
                // 新的消息过来
                if (!lastContentId.equals(chatId) || size != mSize) {
                  if (adapter == null) {

                    adapter = new ChatAdapter(mContext, patient_content, doctor_content);
                    chat_record_list.setAdapter(adapter);
                  } else {
                    adapter.updateData(patient_content, doctor_content);
                  }
                  // chat_record_list.setAdapter(adapter);
                  chat_record_list.setSelection(patient_content.size() - 1);
                  size = mSize;
                  lastContentId = chatId;
                }
              }
            }
          }

          @Override
          public void onResponseEndErr(
              GetChatRecordReq commonReq,
              GetChatRecordRes commonRes,
              String errmsg,
              int responseCode) {
            // TODO Auto-generated method stub

          }
        });
  }