Android 优化光标适配器

Android 优化光标适配器,android,listview,cursor,Android,Listview,Cursor,我试图从数据库中获取数据(大约20k行)并在listview中显示。 我正在使用cursorloader+cursoradapter: 所有的工作都很好,但是当我快速滚动listview时,它仍然滞后。 这是我的游标适配器: public class IssueCursorAdapter extends CursorAdapter { private LayoutInflater inflater; private Context mContext; public IssueCursorAdap

我试图从数据库中获取数据(大约20k行)并在listview中显示。 我正在使用cursorloader+cursoradapter: 所有的工作都很好,但是当我快速滚动listview时,它仍然滞后。 这是我的游标适配器:

public class IssueCursorAdapter extends CursorAdapter {
private LayoutInflater inflater;
private Context mContext;
public IssueCursorAdapter(Context context, Cursor c) {
    super(context, c);
    inflater = LayoutInflater.from(context);
    mContext = context;
}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    ViewHolder holder = new ViewHolder();
    View view = inflater.inflate(R.layout.item_issue, parent, false);
    holder.tvIssueStatus = (TextView) view.findViewById(R.id.tvIssueStatus);
    ...same code

    view.setTag(holder);
    return view;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
    ViewHolder holder = (ViewHolder) view.getTag();

    holder.tvIssueStatus.setText(cursor.getString(cursor.getColumnIndex("StatusDesc")));
    .......same code
}
private static class ViewHolder {
    TextView tvIssueStatus;
    TextView tvIssueType;
            ...same code
}
}
如何优化它?

最好使用a,也请通过 下面是我使用字母索引器的实现:

  private class CurAdapter extends CursorAdapter implements SectionIndexer{

    AlphabetIndexer mAlphabetIndexer;

    public CurAdapter(Context context, Cursor c, int flags) {
        super(context, c, flags);

        mAlphabetIndexer = new AlphabetIndexer(c,
                c.getColumnIndex("Name"),"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
        mAlphabetIndexer.setCursor(c);

    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {

        ((TextView) view.getTag(R.id.textView1)).setText(cursor.getString(cursor.getColumnIndexOrThrow("Name")));

        String manuplate = dateConvert(cursor.getString(cursor.getColumnIndexOrThrow("BirthDate")));
        if(manuplate.contains("0001")){
            manuplate = manuplate.replace("0001", "");
        }

        ((TextView) view.getTag(R.id.textView2)).setText((manuplate));
        ((TextView) view.getTag(R.id.textView1)).setTypeface(tf, Typeface.BOLD);
        ((TextView) view.getTag(R.id.textView2)).setTypeface(tf1); 

        String image = cursor.getString(cursor.getColumnIndexOrThrow("imageUri"));
        System.out.println("Image Uri is:"+image);
        if(image.contains("jpg") || image.contains("png")){
            
            
            /*  File IMG_FILE = new File(image);
            Options options = new BitmapFactory.Options();
            options.inScaled = false;
            options.inDither = false;
            options.inPreferredConfig = Bitmap.Config.ARGB_8888;
            Bitmap bitmap = BitmapFactory.decodeFile(IMG_FILE.getAbsolutePath(), options);*/

            File f = new File(image);
            Bitmap bmp = BitmapFactory.decodeFile(f.getAbsolutePath());
            ((ImageView) view.getTag(R.id.imageView1)).setImageBitmap(bmp); 
            
            
        }else{
            Uri IMAGE_URI = Uri.parse(image);
            IMAGE_URI= Uri.withAppendedPath(IMAGE_URI, Contacts.Photo.CONTENT_DIRECTORY);
            try{
                ((ImageView) view.getTag(R.id.imageView1)).setImageURI(IMAGE_URI);

            }catch (Exception e){
                System.out.println(e);
            }

        }
        ///Buffered stream handling if no image is present display a default image. 
        if (((ImageView) view.getTag(R.id.imageView1)).getBackground()== null){
            ((ImageView) view.getTag(R.id.imageView1)).setBackgroundResource(R.drawable.default_img); 
        }
    }
    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {

        View view = LayoutInflater.from(context).inflate(R.layout.contacts_list, null);

        TextView tv = (TextView) view.findViewById(R.id.textView1);
        TextView tv1 = (TextView) view.findViewById(R.id.textView2);
        ImageView iv = (ImageView) view.findViewById(R.id.imageView1);

        view.setTag(R.id.textView1, tv);
        view.setTag(R.id.textView2, tv1);
        view.setTag(R.id.imageView1, iv);
        return view;
    }

    @Override
    public int getPositionForSection(int sectionIndex) {

        return mAlphabetIndexer.getPositionForSection(sectionIndex);
    }

    @Override
    public int getSectionForPosition(int position) {

        return mAlphabetIndexer.getSectionForPosition(position);
    }

    @Override
    public Object[] getSections() {

        return mAlphabetIndexer.getSections();
    }
}

您可以使用标记模式而不是持有者模式,我认为这会使它更快一些。(未经测试)你能举个例子吗?但最好的办法是使用惰性列表。