@Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); int count = lv.getChildCount(); for (int i = 0; i < count; i++) { LinearLayout linearLayout = (LinearLayout) lv.getChildAt(i); LinearLayout linearLayoutChild = (LinearLayout) linearLayout.getChildAt(0); EditText editText = (EditText) linearLayoutChild.getChildAt(1); if (editText.isShown()) { String value = editText.getText().toString(); EnterCompanyListAdapter.ViewHolder viewHolder = (ViewHolder) linearLayout.getTag(); viewHolder.fieldAndAnswer.set(1, value); } } @SuppressWarnings("unused") int count2 = epla.getCount(); for (int i = 0; i < epla.getCount(); i++) { @SuppressWarnings("unchecked") ArrayList<String> fieldAndAnswer = (ArrayList<String>) epla.getItem(i); String fieldName = fieldAndAnswer.get(0); String value = fieldAndAnswer.get(1); company.set(fieldName, value); } outState.putSerializable("company", company); outState.putSerializable("person", person); outState.putBoolean("personLinked", personLinked); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case GET_PERSON_ID: person = (Person) data.getSerializableExtra("person"); person.toString(); company.set("person", person.get("id")); Log.v("TeamLeader", "this company will be linked to person: " + person.get("id")); linkPersonEditText.setText(person.getName()); linkPersonEditText.setTag(person); break; } }
public void commitCompany(View arg0) { // print out all of the properties of this Company Log.v("TeamLeader", "results \n" + company.toString()); // go through and make sure we got all of the showing fields entered for (int i = 0; i < lv.getChildCount(); i++) { LinearLayout tempLL = (LinearLayout) lv.getChildAt(i); LinearLayout innerLL = (LinearLayout) tempLL.getChildAt(0); EditText tempEditText = (EditText) innerLL.getChildAt(1); EnterCompanyListAdapter.ViewHolder viewHolder = (ViewHolder) tempLL.getTag(); ((ArrayList<String>) (viewHolder.fieldAndAnswer)).remove(1); viewHolder.fieldAndAnswer.add(tempEditText.getText().toString()); } for (int i = 0; i < epla.getCount(); i++) { // LinearLayout tempLL = (LinearLayout)lv.getChildAt(i); // LinearLayout innerLL = (LinearLayout)tempLL.getChildAt(0); // EditText tempEditText = (EditText)innerLL.getChildAt(1); @SuppressWarnings("unchecked") ArrayList<String> fieldAndAnswer = (ArrayList<String>) epla.getItem(i); String fieldName = fieldAndAnswer.get(0); String answer = fieldAndAnswer.get(1); company.set(fieldName, answer); } progressDialog = new ProgressDialog(this); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.setMessage("Communicating with server"); progressDialog.setCancelable(true); // send the instruction to add the Company with the TeamLeader API RESTfulAPI restAPI = new RESTfulAPI(this, null, progressDialog); try { personLinked = false; restAPI.addCompany(company); if (!personLinked && person != null) finish(); } catch (IncompleteCompanyException e) { Toast.makeText(this, "Incomplete Company: required - name ", Toast.LENGTH_LONG).show(); } }
@Override public void onFocusChange(View arg0, boolean arg1) { Log.v("TeamLeader", "onFocusChange received"); // Change the value of the appropriate value in our company if (!arg1) { LinearLayout ll = (LinearLayout) arg0.getParent(); TextView tv = (TextView) ll.getChildAt(0); String key = tv.getText().toString(); EditText editText = (EditText) ll.getChildAt(1); String value = editText.getText().toString(); View parent = (View) arg0.getParent().getParent(); ViewHolder viewHolder = (ViewHolder) parent.getTag(); viewHolder.fieldAndAnswer.remove(1); viewHolder.fieldAndAnswer.add(new String(value)); if (viewHolder != null) { company.set(key, value); // int position = viewHolder.position; Log.v("TeamLeader", "Setting " + key + " to " + value); } } }