/** * Returns the static (for viewing only) {@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 getStaticView(int viewIndex, View convertView, ViewGroup parent) { View newView; if (convertView != null) { // Re-use the given view newView = convertView; } else { // Instantiate a new view newView = inflater.inflate(R.layout.req_view_elem, null); } final Requirement req = (Requirement) getItem(viewIndex); ((TextView) newView.findViewById(R.id.reqDescriptionText)).setText(req.getDescription()); // Figure out what Image resource to set int resource; switch (req.getContentType()) { case text: resource = R.drawable.txticon; break; case image: resource = R.drawable.imgicon; break; case audio: resource = R.drawable.audicon; break; case video: resource = R.drawable.vidicon; break; default: Log.w("RequirementListAdapter", "Unknown Content Type: " + req.getContentType()); resource = R.drawable.txticon; } // Set the image ((ImageView) newView.findViewById(R.id.reqContentImg)).setImageResource(resource); // Set Fulfillment handler ((Button) newView.findViewById(R.id.reqFulfillBtn)) .setOnClickListener( new OnClickListener() { public void onClick(View source) { openFulfillmentActivity(req); } }); return newView; }
/** * 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; }