public void notifyItemUpdated() { ranker.rank(items); notifyDataSetChanged(); updateHint(); }
public View getView(final int i, View convertView, ViewGroup viewgroup) { final ShoppingItem item = items.get(i); View view = inflater.inflate(R.layout.item_view, null); TextView priceView = (TextView) view.findViewById(R.id.price); TextView rankView = (TextView) view.findViewById(R.id.rank); TextView quantityView = (TextView) view.findViewById(R.id.quantity); TextView ratioView = (TextView) view.findViewById(R.id.ratio); CheckBox enabledBox = (CheckBox) view.findViewById(R.id.enabled); NumberFormat format = NumberFormat.getCurrencyInstance(); priceView.setText(format.format(item.getPrice())); quantityView.setText(item.getQuantity().toString()); enabledBox.setChecked(item.isEnabled()); if (item.isEnabled()) { try { int rank = ranker.getRank(item); if ((rank > 0) && (rank <= rankName.length)) { rankView.setText(rankName[rank - 1]); if (rank <= 3) { rankView.setTextColor(Color.rgb(0, 153, 0)); // dark green } } if (rank > 1) { ratioView.setText("+" + numberFormat.format(ranker.getRatioToBestPrice(item) - 1)); } } catch (UncomparableUnitException e) { rankView.setText(R.string.uncomparable); rankView.setTextColor(Color.RED); } } else { priceView.setEnabled(false); } enabledBox.setOnCheckedChangeListener( new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton button, boolean isChecked) { item.setEnabled(isChecked); notifyItemUpdated(); } }); view.setOnClickListener( new OnClickListener() { @Override public void onClick(View paramView) { startEditItemActivity(i); } }); view.setOnCreateContextMenuListener( new OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) { menu.add(Menu.NONE, i, MENU_DELETE, getString(R.string.delete_item)); } }); return view; }