我有问题。抱歉英文不好。
我的Android应用程序在滚动列表并按下任何按钮后崩溃了。 在堆栈跟踪中:
The content of the adapter has changed but ListView did not receive a notification.
Make sure the content of your adapter is not modified from a background thread, but only from the UI thread.
Make sure your adapter calls notifyDataSetChanged() when its content changes.
适配器的内容未发生变化。滚动并单击其中的另一个按钮时会发生错误。单击按钮后使用相同的listView,但内容不同。
这是我的代码: CustomAdapter.getView
private ArrayList<ListData> eventsRecommended;
private ArrayList<ListData> eventsAll;
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
View rowView = convertView;
if ( rowView == null )
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
rowView = inflater.inflate(R.layout.inetlist, null, true);
holder = new ViewHolder();
holder.eventTitle = (TextView) rowView.findViewById(R.id.title);
holder.eventDescription = (TextView) rowView.findViewById(R.id.description);
holder.eventImage = (ImageView) rowView.findViewById(R.id.imageView1);
holder.eventTickets = (Button) rowView.findViewById(R.id.buyTicketButton);
rowView.setTag(holder);
}
else
{
holder = (ViewHolder) rowView.getTag();
}
ListData p = getItem(position);
holder.eventTitle.setText(p.title);
holder.eventDescription.setText(p.description);
if ( p.ticketLink == null || p.ticketLink.length() < 1 )
holder.eventTickets.setVisibility(View.INVISIBLE);
else
holder.eventTickets.setVisibility(View.VISIBLE);
holder.eventTickets.setOnClickListener(onClickListener);
holder.eventImage.setImageDrawable(getDrawable(p.pic));
return rowView;
}
按钮点击更改标志的布尔值
public ListData getItem(int position)
{
try
{
if (flag == Boolean.FALSE)
return eventsRecommended.get(position);
else
return eventsAll.get(position);
}
catch (Exception e) {}
return null;
}
答案 0 :(得分:0)
单击按钮后尝试使用其他自定义列表视图适配器。 它会崩溃吗? 可能有问题吗?