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 CurrentJobActivity extends BaseActivity { private View view = null; private LinearLayout wr_areas; private BaseThread thread; private EditText searchText; private ImageView search,add; public int clicknum = 880000; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.current_job); view = getLayoutInflater().inflate(R.layout.current_job, null); search = (ImageView) findViewById(R.id.search); search.setOnClickListener(onClickListener); add = (ImageView) findViewById(R.id.add); add.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("")){ getCurrentList(); } } }); getCurrentList(); } private View.OnClickListener onClickListener = new View.OnClickListener() { @Override public void onClick(View arg0) { if (arg0 == search) { getCurrentList(); } else if(arg0 == add){ Intent intent = new Intent(CurrentJobActivity.this, AddJobActivity.class); startActivity(intent); } } }; @Override public void finish() { super.finish(); overridePendingTransition(0, 0); } public void getCurrentList() { wr_areas.removeAllViews(); thread = new BaseThread(baseHandler) { @Override public void runThread() { final Message msg = thread.obtainMessage(); if (msg != null) { msg.what = HandlerStatus.HANDLE_CURRENTLIST; try { ApiClent.currentList(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.arg1 = HandlerStatus.HANDLE_NULL; msg.obj = jsonArray; // Msg.showInfo(CurrentJobActivity.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 protected void onCancelProgress(DialogInterface arg0) { if (thread != null) { thread.interrupt(); } CurrentJobActivity.this.finish(); } @Override protected void handleMessage(Message msg) { if (msg.what == HandlerStatus.HANDLE_CURRENTLIST) { 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_view0, null); TextView index = (TextView) llWashingRoomItem.findViewById(R.id.index); TextView name = (TextView) llWashingRoomItem.findViewById(R.id.name); TextView status = (TextView) llWashingRoomItem.findViewById(R.id.status); TextView starttime = (TextView) llWashingRoomItem.findViewById(R.id.starttime); index.setText(Integer.toString(i+1)); name.setText(json.getString("jobPosition")); status.setText(json.getString("statusName")); 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.7f); status.setLayoutParams(lp); lp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f); 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(CurrentJobActivity.this, CurrentMapActivity.class); Bundle bundle = new Bundle(); try { bundle.putString("data", jsonArray.getJSONObject(i-clicknum).toString()); }catch (JSONException e){ e.printStackTrace(); } intent.putExtras(bundle); startActivityForResult(intent,0x006); } }); wr_areas.addView(llWashingRoomItem); } }catch (Exception e){ Msg.showInfo(CurrentJobActivity.this, "获取当前作业列表时出错!"); } } } else { // Msg.showInfo(CurrentJobActivity.this, "获取当前作业列表时出错!"); Msg.showInfo(CurrentJobActivity.this, "未查询到任何项"); } closeProgress(); } } }