繁体   English   中英

如何在Android中的SQLite数据库中以列表视图显示图像

[英]How to diaplay image in listview from sqlite database in android

如何在sqlite db的列表视图中显示图像

 SimpleCursorAdapter adapter;
    adapter = new SimpleCursorAdapter(MainActivity.this, R.layout.activity_column, c
            ,new String[] {"MemberID","Name","Tel","Photo"}
            ,new int[] {R.id.textView1, R.id.textView2, R.id.textView3, R.id.imageview}); 

此代码工作没有图像,但我从照片中调用图像时出现错误。 如何在列表视图中显示图像。

您需要具有自己的自定义光标适配器。

您这个提示:

public class CustomListViewCursorAdapter extends SimpleCursorAdapter {

    private static final String LOG_TAG = CustomListViewCursorAdapter.class.getSimpleName();


    String[] from;

    int[] to;

    Context context;

    public CustomListViewCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags){

        super(context, layout, c, from, to, flags);

        this.from = from;
        this.to = to;

    }

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

        try {

            for( int i = 0; i < to.length; ++i){

                int columnIndex = cursor.getColumnIndex(from[i]);

                String columnValue = cursor.getString(columnIndex);

                TextView textView = (TextView) view.findViewById(to[i]);

                textView.setText(columnValue);

            }


            //get your image view and set its content here.
            view.findViewById(R.id.photo).setImageBitmap(yourImageBitmap);

        } catch (IllegalArgumentException e) {

            Log.e(LOG_TAG, e.getMessage(), e);

        }

    }



}

恐怕您将不得不编写自己的布局并使用自定义适配器:

http://developer.android.com/guide/topics/ui/declaring-layout.html

这是可以帮助您的教程: http : //www.vogella.com/tutorials/AndroidListView/article.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM