如何使用的CursorAdapter? [英] How to use CursorAdapter?

查看:139
本文介绍了如何使用的CursorAdapter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这个问题的标题是否合适与否,但搜索了很多后,我问这个。

I am not sure whether the question title is proper or not, but after searching a lot I am asking this.

在我的SQLite表,我有列

In my SQLite table, I have the columns

1: _id   2: position   3: path

position: the position of the gridView where the Image is to set
path:  the path of the SDCard having corresponding image

我怎么会得到从路径的形象,并设置成在GridView

How would I get the image from the path and set into the GridView

GridView grid = (GridView) findViewById(R.id.play_grid_view);
DBAdapter adapter = new DBAdapter(this); //My costum adapter for databse operation
adapter.open();
Cursor cusor = adapter.getAllImages(); //returns cursor with 3 columns mentioned above
startManagingCursor(cusor);

在这之后我该怎么办?

After this what should I do?

推荐答案

如果你的位置列表示图像的网格中的位置,你可以排序你的这个查询栏,然后CursorAdapter的将根据您的数据库设置位置填写您的网格。

If your position column means the position of image in grid, you can just sort your query with this column, then cursorAdapter will fill your grid according to positions set in your DB.

这是不是有用,如果你跳过某些gridview的细胞(假设你已经按照你的数据库的位置:1,2,4 - 那么你的这个适配器将填补职位空缺1,2,3一样居然没有任何位置检查)

This is not usable, if you will skip some of gridview cells (suppose you have following positions in your database: 1,2,4 - then your this adapter will fill positions 1,2,3 as there is actually no position checking)

public class ImageCursorAdapter extends CursorAdapter {
    public ImageCursorAdapter(Context context, Cursor c) {
        super(context, c);
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        String pos = cursor.getString(positionColumnIndex);
        String path = cursor.getString(pathColumnIndex);
        ImageView image = (ImageView)view;
        image.setImageDrawable(Drawable.createFromPath(path));
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        View v = new ImageView(context);
        bindView(v, context, cursor);
        return v;
    }
}

这篇关于如何使用的CursorAdapter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆