Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Listview自定义适配器_Android_Sqlite_Listview_Simplecursoradapter_Custom Adapter - Fatal编程技术网

Android Listview自定义适配器

Android Listview自定义适配器,android,sqlite,listview,simplecursoradapter,custom-adapter,Android,Sqlite,Listview,Simplecursoradapter,Custom Adapter,我使用SimpleCursorAdapter从SQLite数据库检索数据,并使用自定义布局和listview显示数据库中的两个字符串。现在我有两个问题: 如果我想根据特定条件在特定行中显示星形,是否必须创建自定义适配器?我已经在自定义布局中将图像设置为不可见,并希望根据行数据本身的某些条件将其设置为可见。我实现了所有的标签以及收藏夹标签,并且都正常工作,我只需要星形图标。我还面临将配方图像放到特定行的问题 在ListView中动态获取图像的最佳方法是什么?我已经学习了lazy image教程,但

我使用SimpleCursorAdapter从SQLite数据库检索数据,并使用自定义布局和listview显示数据库中的两个字符串。现在我有两个问题:

  • 如果我想根据特定条件在特定行中显示星形,是否必须创建自定义适配器?我已经在自定义布局中将图像设置为不可见,并希望根据行数据本身的某些条件将其设置为可见。我实现了所有的标签以及收藏夹标签,并且都正常工作,我只需要星形图标。我还面临将配方图像放到特定行的问题

  • 在ListView中动态获取图像的最佳方法是什么?我已经学习了lazy image教程,但我不知道如何使用CustomCursorAdapter实现它,因为它是使用baseadapter实现的。有哪些链接指向懒散加载simplecursor教程中的图像

  • 我必须创建自定义适配器吗

    是的,您必须创建自定义适配器并在行中添加星形

    在ListView中动态获取图像的最佳方法是什么


    我认为你应该使用通用图像加载器。查看项目。

    感谢萨米尔的回答。我将尝试看看通用图像加载器。你有什么例子可以说明我如何使用自定义适配器来完成我的任务吗?此外,我还为自定义适配器中没有选项卡的列表编写了活动中的所有代码。Mohamed,我没有任何示例来完成您的所有任务,但看到了带有图像的自定义适配器。我用代码编辑了我的问题,我正在尝试,但出现了一个错误。谢谢Samir。它还使用baseAdapter.images是静态的或从URLMimages获取的。在drawable文件夹中,images是静态的
    public class AlternateRowCursorAdapter extends SimpleCursorAdapter{
        int layoutn;
        Cursor mCursor;
        String[] fromn;
        int[] ton;
    
        LayoutInflater mInflater;
    
        private int[] colors = new int[] { Color.parseColor("#000000"), Color.parseColor("#303030") };
    
        public AlternateRowCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
            super(context, R.layout.listtype, c, from, to);
            this.mCursor = c;
        }
    
        /**
         * Display rows in alternating colors
         */
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
    
            View view = super.getView(position, convertView, parent);
    
            ImageView star = (ImageView)view.findViewById(R.id.favoritesicon); // The star I want to show
    
            if (mCursor.getString(8) == "YES") // shows if the item is in favorites
            {
                star.setVisibility(view.VISIBLE);
            }
    
            int colorPos = position % colors.length;
            view.setBackgroundColor(colors[colorPos]);
    
            return view;
        }
    }