public static RequirementTextWatcher getWatcher( int position, View v, RequirementListAdapter rla) { if (watchers == null) watchers = new HashMap<View, RequirementTextWatcher>(); RequirementTextWatcher w = watchers.get(v); if (w == null) { w = new RequirementTextWatcher(position, rla); watchers.put(v, w); } else { w.position = position; } return w; }
/** * Returns an editable {@link View} of a requirement. * * @param viewIndex the index of the requirement * @param convertView the old view * @param parent the parent view * @return the static View */ public View getEditView(int viewIndex, View convertView, ViewGroup parent) { View newView; if (convertView != null) { // Re-use the given view newView = convertView; // Just ask it to update the position of the Watcher RequirementTextWatcher.getWatcher(viewIndex, newView, this); } else { // Instantiate a new view newView = inflater.inflate(R.layout.req_edit_elem, null); // Setup the EditText watcher ((EditText) newView.findViewById(R.id.reqDescriptionEdit)) .addTextChangedListener(RequirementTextWatcher.getWatcher(viewIndex, newView, this)); } final Requirement req = (Requirement) getItem(viewIndex); ((EditText) newView.findViewById(R.id.reqDescriptionEdit)).setText(req.getDescription()); // Figure out what Image resource to set int resource; if (req.getContentType() == contentType.text) { resource = R.drawable.txticon; } else if (req.getContentType() == contentType.image) { resource = R.drawable.imgicon; } else if (req.getContentType() == contentType.audio) { resource = R.drawable.audicon; } else if (req.getContentType() == contentType.video) { resource = R.drawable.vidicon; } else { Log.w("RequirementListAdapter", "Unknown Content Type: " + req.getContentType()); resource = R.drawable.txticon; } // Set the image ((ImageView) newView.findViewById(R.id.reqContentImg)).setImageResource(resource); // Enable the delete button ((Button) newView.findViewById(R.id.reqDeleteBtn)) .setOnClickListener( new OnClickListener() { public void onClick(View source) { task.removeRequirement(req); update(); } }); return newView; }