package com.casic.gasoperation; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.os.Message; import android.text.Editable; import android.text.TextWatcher; import android.view.View; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; import com.casic.gasoperation.config.ApiClent; import com.casic.gasoperation.utils.BaseThread; import com.casic.gasoperation.utils.HandlerStatus; import com.casic.gasoperation.utils.Msg; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public class HistoryJobActivity extends BaseActivity { private View view = null; private LinearLayout wr_areas; private BaseThread thread; private EditText searchText; private ImageView search; public int clicknum = 880000; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.history_job); view = getLayoutInflater().inflate(R.layout.history_job, null); search = (ImageView) findViewById(R.id.search); search.setOnClickListener(onClickListener); wr_areas=(LinearLayout) findViewById(R.id.wr_areas); searchText = (EditText) findViewById(R.id.search_adress); searchText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { if(searchText.getText().equals("")){ getHistoryList(); } } }); getHistoryList(); } private View.OnClickListener onClickListener = new View.OnClickListener() { @Override public void onClick(View arg0) { if (arg0 == search) { getHistoryList(); } } }; public void getHistoryList() { wr_areas.removeAllViews(); thread = new BaseThread(baseHandler) { @Override public void runThread() { final Message msg = thread.obtainMessage(); if (msg != null) { msg.what = HandlerStatus.HANDLE_HISTORYLIST; try { ApiClent.historyList(searchText.getText().toString(),1,100,new ApiClent.ClientCallback() { @Override public void onSuccess(Object data) { try { JSONObject jsonObject = new JSONObject(data.toString()); JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("rows"); if (jsonArray.length()== 0) { Msg.showInfo(HistoryJobActivity.this, "未查询到任何项"); return ; }else{ msg.arg1 = HandlerStatus.HANDLE_OK; msg.obj = jsonArray; } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public void onFailure(String message) { msg.arg1 = HandlerStatus.HANDLE_FAIL; } @Override public void onError(Exception e) { msg.arg1 = HandlerStatus.HANDLE_ERROR; } }); } catch (Exception e) { msg.arg1 = HandlerStatus.HANDLE_ERROR; e.printStackTrace(); } thread.sendMessage(msg); } } }; showProgress("历史作业列表查询中。。。", "历史作业"); thread.start(); } @Override public void finish() { super.finish(); overridePendingTransition(0, 0); } @Override protected void onCancelProgress(DialogInterface arg0) { if (thread != null) { thread.interrupt(); } HistoryJobActivity.this.finish(); } @Override protected void handleMessage(Message msg) { if (msg.what == HandlerStatus.HANDLE_HISTORYLIST) { if (msg.arg1 == HandlerStatus.HANDLE_OK) { if (msg.obj != null) { try { final JSONArray jsonArray = (JSONArray) msg.obj; for(int i=0;i<jsonArray.length();i++){ JSONObject json = jsonArray.getJSONObject(i); LinearLayout llWashingRoomItem = new LinearLayout(view.getContext()); llWashingRoomItem.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT)); llWashingRoomItem = (LinearLayout) getLayoutInflater().inflate(R.layout.table_view1, null); TextView index = (TextView) llWashingRoomItem.findViewById(R.id.index); TextView name = (TextView) llWashingRoomItem.findViewById(R.id.name); TextView endtime = (TextView) llWashingRoomItem.findViewById(R.id.endtime); TextView starttime = (TextView) llWashingRoomItem.findViewById(R.id.starttime); index.setText(Integer.toString(i+1)); name.setText(json.getString("jobPosition")); endtime.setText(json.getString("endTime")); starttime.setText(json.getString("startTime")); //动态设置layout_weight权重设置表格宽度 LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 0.5f); index.setLayoutParams(lp); lp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f); name.setLayoutParams(lp); lp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 0.8f); endtime.setLayoutParams(lp); starttime.setLayoutParams(lp); llWashingRoomItem.setTag(clicknum+i); llWashingRoomItem.setClickable(true); llWashingRoomItem.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { int i = (Integer) v.getTag(); //这里的i不能在外部定义,因为内部类的关系,内部类好多繁琐的东西,要好好研究一番 Intent intent = new Intent(); intent.setClass(HistoryJobActivity.this, HistoryAlarmActivity.class); Bundle bundle = new Bundle(); try { bundle.putString("id", jsonArray.getJSONObject(i-clicknum).getString("id")); }catch (JSONException e){ e.printStackTrace(); } intent.putExtras(bundle); startActivityForResult(intent,0x006); } }); wr_areas.addView(llWashingRoomItem); } }catch (Exception e){ Msg.showInfo(HistoryJobActivity.this, "获取历史作业列表时出错!"); } } } else { Msg.showInfo(HistoryJobActivity.this, "获取历史作业列表时出错!"); } closeProgress(); } } }