/** 添加子项 */ public void addItem( String disSn, String gmsId, String gmyId, String gmyName, String mFbsjDate, String zlms, String fbyyString) { final ListItemYwgmsCommon listItem = new ListItemYwgmsCommon(mContext); // List<Integer> widths = new ArrayList<Integer>(); // widths.add(177); // widths.add(137); // widths.add(158); // widths.add(236); // widths.add(236); // widths.add(118); // Log.i(TAG, "addItem: " + widths.toString()); // listItem.setViewByWidths(widths); mListView.add(listItem); getView(mListView.size() - 1, listItem, JbxxYwgmsLayout.this); listItem.setIndex(mListView.size() - 1); String gmsName = ResourcesFactory.findValue(mContext, "gmzl", gmsId); listItem.setDisSn(disSn); listItem.setGmsId(gmsId); listItem.setGmsName(gmsName); listItem.setGmyId(gmyId); listItem.setmGmyName(gmyName); listItem.setmDate(mFbsjDate); listItem.setFbyy(fbyyString); listItem.setZlms(zlms); // addView(listItem); mListAdapter.notifyDataSetChanged(); // invalidate(); }
/** * 移除子项 * * @param position */ public void removeItem(int position) { ListItemYwgmsCommon listItem = mListView.get(position); // removeView(listItem); // invalidate(); mListView.remove(position); // 更新索引 for (int i = position; i < mListView.size(); i++) { listItem = mListView.get(i); listItem.setIndex(i + 1); listItem.setTag(i); } mListAdapter.notifyDataSetChanged(); }
/** 更新子项 */ public void updateItem( int position, String gmsId, String gmyId, String gmyName, String mFbsjDate, String zlms, String fbyyString) { final ListItemYwgmsCommon listItem = mListView.get(position); String gmsName = ResourcesFactory.findValue(mContext, "gmzl", gmsId); listItem.setGmsId(gmsId); listItem.setGmsName(gmsName); listItem.setGmyId(gmyId); listItem.setmGmyName(gmyName); listItem.setmDate(mFbsjDate); listItem.setFbyy(fbyyString); listItem.setZlms(zlms); mListAdapter.notifyDataSetChanged(); }
public void editItem(final int position) { changePosition = position; selectDialog = new Dialog(mContext, R.style.dialog); selectDialog.setCancelable(true); selectDialog.setContentView(R.layout.dialog_add_gms_layout); // LayoutInflater inflater = LayoutInflater.from(mContext); // final View textEntryView = inflater.inflate( // R.layout.jbxx_ywgms_alertdialog, null); gmsSpinnerUtil = (SpinnerUtil) selectDialog.findViewById(R.id.gmsSpinner); gmySpinnerUtil = (SpinnerUtil) selectDialog.findViewById(R.id.gmySpinner); fbsjCalendarText = (CalendarText) selectDialog.findViewById(R.id.fbsjCalendarText); fbyyEditText = (EditText) selectDialog.findViewById(R.id.fbyyEditText); zlmsEditText = (EditText) selectDialog.findViewById(R.id.zlmsEditText); qdButton = (Button) selectDialog.findViewById(R.id.qdButton); qxButton = (Button) selectDialog.findViewById(R.id.qxButton); closeImageView = (ImageView) selectDialog.findViewById(R.id.closeImageView); closeImageView.setOnClickListener( new android.view.View.OnClickListener() { @Override public void onClick(View arg0) { selectDialog.dismiss(); // 隐藏对话框 } }); // ArrayAdapter<String> adapter = null; // adapter = new ArrayAdapter<String>(mContext, // R.layout.simple_spinner_item, getResources().getStringArray( // R.array.gmszl_conditions)); // adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // gmsSpinner.setAdapter(adapter); // 把以前的信息加载进来现在出来 final ListItemYwgmsCommon listItem = mListView.get(position); // final ArrayList<String> gmyNameList = new ArrayList<String>();// 存储过敏原名称的list // final ArrayList<String> gmyIdList = new ArrayList<String>();// 存储过敏原id的list // final ArrayAdapter<String> mGmyAdapter = new ArrayAdapter<String>( // mContext, R.layout.simple_spinner_item, gmyNameList); // mGmyAdapter // .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // gmySpinner.setAdapter(mGmyAdapter); gmsSpinnerUtil.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { setGmySpinnerUtil(gmsSpinnerUtil.getSelectedValue()); } @Override public void onNothingSelected(AdapterView<?> parent) {} }); // 过敏史种类 gmsSpinnerUtil.setSelectedPositionByData(listItem.getGmsName()); // 初始化过敏原列表 setGmySpinnerUtil(gmsSpinnerUtil.getSelectedValue()); gmySpinnerUtil.setSelectedPositionByData(listItem.getmGmyName()); // 发病时间 fbsjCalendarText.setText(listItem.getDate()); fbyyEditText.setText(listItem.getFbyy()); zlmsEditText.setText(listItem.getZlms()); qdButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View arg0) { String gmsId = gmsSpinnerUtil.getSelectedValue(); // 过敏史的种类 String gmyId = "", gmyName = ""; // 过敏原 if (gmySpinnerUtil.getCount() > 0) { gmyId = gmySpinnerUtil.getSelectedValue(); gmyName = gmySpinnerUtil.getSelectedData(); } if (gmyId.equals("") || gmyName.equals("")) { Toast.makeText(mContext, "过敏源不能为空", Toast.LENGTH_SHORT).show(); return; } String fbyyString = fbyyEditText.getText().toString(); String mFbsjDate = fbsjCalendarText.getText().toString(); if (fbsjCalendarText.equals("")) { Toast.makeText(mContext, "发病时间不能为空", Toast.LENGTH_SHORT).show(); return; } String zlms = zlmsEditText.getText().toString(); // 添加子项 ListItemYwgmsCommon listItem = mListView.get(position); getJmjbxxFromDb( listItem.getDisSn(), gmsId, gmyId, gmyName, mFbsjDate, zlms, fbyyString, 2); selectDialog.dismiss(); } }); qxButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View arg0) { selectDialog.dismiss(); } }); selectDialog.show(); }