小编Den*_*nie的帖子

从android中的光标获取所有项目

我使用此代码从光标获取项目,但它只返回列表中的一个项目.那么,我怎样才能将所有项目都列入我的列表,这是我的代码?

class MyAdapter extends SimpleCursorAdapter
{
    private Context context;

    public MyAdapter(Context context, int layout, Cursor c, String[] from, int[] to)
    {
        super(context, layout, c, from, to);
        this.context = context;

    }
    public View getView(int position, View convertView, ViewGroup parent){
        Cursor cursor = getCursor();

        LayoutInflater inflater = ((Activity) context).getLayoutInflater();         
        View v = inflater.inflate(R.layout.sbooks_row, null);           
        TextView title = (TextView)findViewById(R.id.title);
        if(title != null){
            int index = cursor.getColumnIndex(SBooksDbAdapter.KEY_TITLE);
            String type = cursor.getString(index);
            title.setText(type);
        }

        TextView lyrics = (TextView)findViewById(R.id.lyrics);
        if(lyrics != null){
            int index = cursor.getColumnIndex(SBooksDbAdapter.KEY_LYRICS); …
Run Code Online (Sandbox Code Playgroud)

android list cursor

2
推荐指数
1
解决办法
1万
查看次数

导出Android应用程序时包含数据库数据

我将我的应用程序导出到.apk文件,签名然后安装它.但是当我运行我的应用程序时,它会显示错误,因为我的数据库中没有数据.

安装应用程序时,数据库是作为新数据库创建的,因此所有数据都丢失了!

导出Android应用程序时如何包含数据库数据?

database android

2
推荐指数
1
解决办法
767
查看次数

如何在android中使用rawQuery()

我有这样的SQL查询

String loadFav = "SELECT _id, title, name, favorite FROM table1 where favorite= 1 " 
                     + "UNION ALL" 
                     + "SELECT _id, title, name, favorite FROM table2 where favorite= 1"
                     ;

    Cursor mCursor = mSQLiteDatabase.rawQuery(loadFav, null);
Run Code Online (Sandbox Code Playgroud)

运行此查询时出错.这是正确的结构吗?有人能帮我吗?

sql android

2
推荐指数
1
解决办法
3万
查看次数

Update ListView(android)之后"刷新"和"setSelection"的更好方法

在我ListView,我选择一个项目"添加收藏夹",我必须做一些工作,我再次填充数据刷新列表,然后我实现OnScrollListener使用setSelection(firstVisibleItem)设置列表显示权限项目添加.

有没有更好的方法来做到这一点.我的意思mCursor.requery()是在Android API中喜欢或类似的东西?或者任何建议的方式?

android listview

2
推荐指数
1
解决办法
6830
查看次数

标签 统计

android ×4

cursor ×1

database ×1

list ×1

listview ×1

sql ×1