我从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;
}
我尝试点击ivIcon
项,listview
的一行将被删除,listview
应该刷新,但我无法刷新listview。我需要帮助
答案 0 :(得分:2)
您的选择是:
实施例
final ArrayAdapter adapter = ((ArrayAdapter)getListAdapter());
runOnUiThread(new Runnable() {
public void run() {
adapter.notifyDataSetChanged();
}
});
答案 1 :(得分:0)
此代码可以帮助您。
假设您有适配器
ListView = listview;
customListView mcustomListView = new customListView(this);
单击getView中的列表项
holder.ivIcon.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
customListView mcustomListView = (customListView ) mlvItem.getAdapter();
mcustomListView .notifyDataSetChanged();
}
}