Reputation: 339
I have a custom adapter extends from arrayadapter:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.list_item, null);
holder = new ViewHolder();
holder.tvName = (TextView) convertView.findViewById(R.id.tvName);
holder.tvPrice = (TextView) convertView.findViewById(R.id.tvPrice);
holder.ivItem = (ImageView) convertView.findViewById(R.id.ivItem);
holder.ivIcon = (ImageView) convertView.findViewById(R.id.ivIcon);
holder.ivArrow = (ImageView) convertView.findViewById(R.id.ivArrow);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.tvName.setText(item.get(position).getName());
holder.tvPrice.setText(item.get(position).getPrice());
holder.ivItem.setImageBitmap(item.get(position).getAvatar());
holder.ivArrow.setImageDrawable(item.get(position).getArrow());
holder.ivIcon.setImageDrawable(item.get(position).getIcon());
holder.ivIcon.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
/*...My code...*/
}
});
return convertView;
}
I try to click on item ivIcon
, a row of listview
will be removed and listview
should refresh, but I don't have way to refresh listview. I need help
Upvotes: 1
Views: 9624
Reputation: 1241
This code will help you.
Suppose that your have adapter like
ListView = listview;
customListView mcustomListView = new customListView(this);
when you click on list item in getView
holder.ivIcon.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
customListView mcustomListView = (customListView ) mlvItem.getAdapter();
mcustomListView .notifyDataSetChanged();
}
}
Upvotes: 0
Reputation: 13785
Your choices are:
Example
final ArrayAdapter adapter = ((ArrayAdapter)getListAdapter());
runOnUiThread(new Runnable() {
public void run() {
adapter.notifyDataSetChanged();
}
});
Upvotes: 3