@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null){ holder = new ViewHolder(); convertView = inflater.inflate(R.layout.filter_dialog_list_row, parent, false); holder.mNameTextView = (TextView) convertView.findViewById(R.id.search_dialog_name_textView); holder.mAbbreviationTextView = (TextView) convertView.findViewById(R.id.search_dialog_abbreviation_textView); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } String s = mArrayList.get(position).getUnitName(); holder.mNameTextView.setText(s); holder.mAbbreviationTextView.setText(mArrayList.get(position).getUnitAbbreviation()); return convertView; }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mSearchDialogBuilder.cancelDialog(); UnitSearchItem item = mSearchDialogBuilder.getItem(position); selectUnitAtUnitArrayPos(item.getUnitPosition(), item.getUnitTypeKey()); } });
@Override public int compare(UnitSearchItem o1, UnitSearchItem o2) { return o1.getUnitName().compareTo(o2.getUnitName()); } });
/** * Helper function for constructors used to collect Units into a list, * and sort the result. * @param items ArrayList of existing units (or empty) * @param unitType Unit Type to find the units from * @param unitTypeKey the key of the the above unit type */ private void UnitListBuilder(ArrayList<UnitSearchItem> items, UnitType unitType, String unitTypeKey) { for (int i = 0; i < unitType.size(); i++) { Unit unit = unitType.getUnitPosInUnitArray(i); // some units are just dummies to help position other units if (unit.toString().equals("") || unit.getLongName().equals("")){ continue; } items.add(new UnitSearchItem(unitTypeKey, unit.getLongName(), unit.getAbbreviation(), i)); } Collections.sort(items, new Comparator<UnitSearchItem>() { @Override public int compare(UnitSearchItem o1, UnitSearchItem o2) { return o1.getUnitName().compareTo(o2.getUnitName()); } }); }
String abbrev = item.getUnitAbbreviation().toLowerCase(); String longName = item.getUnitName().toLowerCase(); String data = longName + " " + abbrev;