Try to use other custom listview adapter after clicking a button. Does it crash with it? Possibly problem in it?
Android app crashed after scrolling the list
-
27-06-2023 - |
Вопрос
I have a problem. Sorry for bad english.
My android app crashed after scrolling the list and pushed any button. In stack trace:
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.
Content of the adapter wasn't changed. The error occurs when scrolling and clicking another button during it. After clicking button used the same listView, but with a different content.
Here is my code: 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;
}
Button's clicking change boolean value of flag
public ListData getItem(int position)
{
try
{
if (flag == Boolean.FALSE)
return eventsRecommended.get(position);
else
return eventsAll.get(position);
}
catch (Exception e) {}
return null;
}
Решение
Не связан с StackOverflow