/** * Implemented method from BaseAdapter class. This method returns the actual data associated with * a row in the list. In this case we return the field along with the field value as a custom * object. We subsequently add the View which displays the value to this object so we can retrieve * it when applying edits. */ public Object getItem(int position) { // get field associated with the position from the editableFieldIndexes // array created at startup int fieldIndex = this.editableFieldIndexes[position]; AttributeItem row = null; // check to see if we have already created an attribute item if not // create // one if (items[position] == null) { // create new Attribute item for persisting the data for subsequent // events row = new AttributeItem(); row.setField(this.fields[fieldIndex]); Object value = this.featureSet.getGraphics()[0].getAttributeValue(fields[fieldIndex].getName()); row.setValue(value); items[position] = row; } else { // reuse existing item to ensure View instance is kept. row = items[position]; } return row; }
/** * Implemented method from BaseAdapter class. This is the main method for returning a View which * corresponds to a row in the list. This calls the getItem() method to get the data. It is called * multiple times by the ListView and may be improved on by saving the previous result. */ public View getView(int position, View convertView, ViewGroup parent) { View container = null; AttributeItem item = (AttributeItem) getItem(position); // check field type // TODO if you want to support domains, add checks here and use the // createSpinnerViewFromArray to create spinners if (item.getField().getName().equals(this.typeIdFieldName)) { // This is the featurelayers type field container = lInflator.inflate(R.layout.item_spinner, null); // get the types name for this feature from the available values String typeStringValue = this.typeMap.get(item.getValue().toString()).getName(); Spinner spinner = createSpinnerViewFromArray(container, item.getField(), typeStringValue, this.typeNames); item.setView(spinner); // TODO set listener to change types associated domain fields if // required } else if (FieldType.determineFieldType(item.getField()) == FieldType.DATE) { // create date picker for date fields container = lInflator.inflate(R.layout.item_date, null); long date = Long.parseLong(item.getValue().toString()); Button dateButton = createDateButtonFromLongValue(container, item.getField(), date); item.setView(dateButton); } else { // create number and text fields // View object for saving in the AttrbuteItem once it has been set // up, for // accessing later when we apply edits. View valueView = null; if (FieldType.determineFieldType(item.getField()) == FieldType.STRING) { // get the string specific layout container = lInflator.inflate(R.layout.item_text, null); valueView = createAttributeRow(container, item.getField(), item.getValue()); } else if (FieldType.determineFieldType(item.getField()) == FieldType.NUMBER) { // get the number specific layout container = lInflator.inflate(R.layout.item_number, null); valueView = createAttributeRow(container, item.getField(), item.getValue()); } else if (FieldType.determineFieldType(item.getField()) == FieldType.DECIMAL) { // get the decimal specific layout container = lInflator.inflate(R.layout.item_decimal, null); valueView = createAttributeRow(container, item.getField(), item.getValue()); } // set the rows view onto the item so it can be received when // applying // edits item.setView(valueView); } return container; }
/* * Count the number of occurrences of attributes combination from the item sets in the ActionDetail * list */ private void countOccurences( ArrayList<AttributeItemSet> tempItemSet, ArrayList<ActionDetail> details) { for (int i = 0; i < details.size(); i++) { ActionDetail ad = details.get(i); for (int j = 0; j < tempItemSet.size(); j++) { AttributeItemSet tempAttrItemSet = tempItemSet.get(j); boolean match = true; for (int k = 0; k < tempAttrItemSet.getCandidateItemSet().size() && match == true; k++) { AttributeItem attrItem = tempAttrItemSet.getCandidateItemSet().get(k); if (attrItem.getAttrName() == "subject") match = attrItem.getAttrValue().equals(ad.getSubject()); else if (attrItem.getAttrName() == "action") match = attrItem.getAttrValue().equals(ad.getAction()); else if (attrItem.getAttrName() == "target") match = attrItem.getAttrValue().equals(ad.getTarget()); else if (attrItem.getAttrName() == "desirability") match = attrItem.getAttrValue().equals(ad.getDesirability() >= 0 ? "positive" : "negative"); else if (attrItem.getAttrName() == "praiseworthiness") match = attrItem .getAttrValue() .equals(ad.getPraiseworthiness() >= 0 ? "positive" : "negative"); else if (attrItem.getAttrName() == "time") match = attrItem.getAttrValue().equals(ad.getTime().getStrRealTime()); } // if all attributes and values in the item set match the values in the action detail, // increase // the coverage for the item set if (match) { tempAttrItemSet.increaseCoverage(); } } } }