Given the item that appears in the ListView,
Can I use its adapter (or ListView itself) to find the view that displays the item?
I am handling the storage of item data and should propagate this change back to the ListView. Adding an element causes it to be displayed using notifyDataSetChanged (), but changed elements are not redrawn using notifyDataSetChanged ()
Here is the code of my activity that edits the element:
@Override
public void onClick(View button) {
EditText text = (EditText)(findViewById(R.id.itemText));
if (item == null) {
ItemsAdapter.instance().items.add(new Item(text.getText().toString()));
} else {
this.item.setTitle(text.getText().toString());
}
ItemsAdapter.instance().notifyDataSetChanged();
this.finish();
}
Relevant parts of my adapter:
public class ItemsAdapter extends BaseAdapter {
ArrayList<Item> items = new ArrayList<Item>();
@Override
public int getCount() {
return items.size();
}
@Override
public Object getItem(int position) {
return items.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Item item = (Item)getItem(position);
ItemTextView textView = null;
if (convertView == null) {
textView = new ItemTextView(context, item);
textView.setOnClickListener(itemListener);
textView.setTextSize(16);
textView.setPadding(5, 5, 5, 5);
} else {
textView = (ItemTextView) convertView;
textView.setItem(item);
}
return textView;
}
}
And the Item class is a POJO that implements Parcelable.
Thanks in advance
Jeff
source
share