gpt4 book ai didi

android - 当我一次又一次滚动 ListView 时应用程序崩溃

转载 作者:太空狗 更新时间:2023-10-29 13:23:27 27 4
gpt4 key购买 nike

我使用了 ListView 并且有超过 65,000 条记录,滚动不是快速和流畅,而且如果我一次又一次地滚动它应用程序崩溃,没有任何错误或任何 ANR 对话框,任何人都可以帮助我来解决这个问题?

我正在使用 SimpleCursorLoaderCursorAdapter 下面是我的代码:

   private static class DotCursorLoader extends SimpleCursorLoader {

private DbHelper mHelper;
private CharSequence filter;

public DotCursorLoader(Context context, DbHelper helper,
CharSequence filter) {
super(context);
mHelper = helper;
this.filter = filter;
}

@Override
public Cursor loadInBackground() {

return mHelper.getCursor(filter);
}

}

private class DotCursorAdapter extends CursorAdapter {

private Context mContext;
private Typeface font;

public class ViewHolder {
TextView txtEng, txtGuj;
}

// public DotCursorAdapter(Context context, Cursor c, int flags) {
// super(context, c, flags);
// mContext = context;
// }

public DotCursorAdapter(Context context, Cursor c,
boolean autoRequery) {
super(context, c, autoRequery);
mContext = context;

}

@Override
public void bindView(View view, Context context,
android.database.Cursor cursor) {
ViewHolder holder = (ViewHolder) view.getTag();
if (LibConstants.isEnglishEnabled(mActivity)) {

holder.txtEng.setTextColor(settings.getInt(
LibConstants.English_Pref_Color_Key,
Color.BLACK));
// txtEng.setTypeface(Typeface.DEFAULT);
holder.txtEng.setTextSize(Integer.parseInt(settings
.getString("TextSize", "20")));
holder.txtEng.setText(LibConstants.getWord(cursor
.getString(1)));
Utils.setEnglishFont(holder.txtEng, mActivity);

holder.txtGuj.setTextColor(settings.getInt(
LibConstants.Mean_Pref_Color_Key,
getResources().getInteger(
R.color.blue)));

holder.txtGuj.setTypeface(font);
holder.txtGuj.setTextSize(Integer.parseInt(settings
.getString("TextSize", "20")));
holder.txtGuj.setText(LibConstants.getWord(cursor
.getString(2)));

} else {

holder.txtEng.setTextColor(settings
.getInt(LibConstants.Mean_Pref_Color_Key,
getResources().getColor(
R.color.blue)));
holder.txtEng.setTypeface(font);
holder.txtEng.setTextSize(Integer.parseInt(settings
.getString("TextSize", "20")));
holder.txtEng.setText((cursor
.getString(2)));

holder.txtGuj.setTextColor(settings.getInt(
LibConstants.English_Pref_Color_Key,
Color.BLACK));
holder.txtGuj.setTypeface(Typeface.DEFAULT);
holder.txtGuj.setTextSize(Integer.parseInt(settings
.getString("TextSize", "20")));
holder.txtGuj.setText(cursor
.getString(1));
Utils.setEnglishFont(holder.txtGuj, mActivity);
}

}

@Override
public View newView(Context context,
android.database.Cursor cursor, ViewGroup parent) {
View view = LayoutInflater.from(mContext).inflate(
R.layout.list_item, parent, false);
ViewHolder viewHolder = new ViewHolder();
viewHolder.txtEng = (TextView) view
.findViewById(R.id.txtEng);
viewHolder.txtGuj = (TextView) view
.findViewById(R.id.txtGuj);
view.setTag(viewHolder);
return view;
}

}

最佳答案

可以在这里找到 Endless Adapter 的最佳示例之一

https://github.com/commonsguy/cwac-endless

关于android - 当我一次又一次滚动 ListView 时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25115922/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com