我遇到了导致我的应用程序崩溃的 ListView 问题。整个应用程序不会崩溃,它只是关闭视图并重新加载主要活动。它看起来工作正常,并且当滚动非常快时,它基本上是稳定的。但是,如果我使用快速滚动多次上下滚动,屏幕将冻结并重新加载主要活动。有人可以帮我找出问题所在吗?这是我从 LogCat 崩溃时收到的错误:
Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 12439 (AsyncTask #4)
这是我的代码:
getView() 方法
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = new ViewHolder();
View vi = convertView;
if (convertView == null) {
vi = inflater.inflate(R.layout.custom_layout, null);
vi.setMinimumHeight(120);
holder = new ViewHolder();
holder.text = (TextView) vi.findViewById(R.id.text);
holder.icon= (ImageView) vi.findViewById(R.id.icon);
vi.setTag(holder);
}
holder = (ViewHolder) vi.getTag();
holder.position = kanji_ids.get(position);
holder.context = vi.getContext();
new DownloadAsyncTask().execute(holder);
return vi;
}
这是获取数据并显示它的 AsyncTask ......
class DownloadAsyncTask extends AsyncTask<ViewHolder, Void, ViewHolder> {
String icon;
String text;
@Override
protected ViewHolder doInBackground(ViewHolder... params) {
ViewHolder viewHolder = params[0];
Context context = viewHolder.context;
Database db = Database.getInstance(context);
text = db.getPercentByPosition(viewHolder.position);
icon = db.getIconByPosition(viewHolder.position);
return viewHolder;
}
@Override
protected void onPostExecute(ViewHolder result) {
if (result.icon == null) {
result.icon.setImageResource(R.drawable.loading);
} else {
result.icon.setImageResource(icon);
}
result.text.setText(text);
}
}