Android游标移动到第一个不填充数据库

时间:2014-08-08 22:21:33

标签: android sqlite

我对Android开发和整个开发都很陌生。我有一个程序,我正在尝试解决。我想我已将问题与以下代码隔离开来:

ArrayList<RSSItem> arrayrssitems = new ArrayList<RSSItem>();
    dataAdapter = new DBAdaptor(this);
    dataAdapter.open();
    mCursor = dataAdapter.getRssItems(dataAdapter
            .getChannelIdFromLink(channelLink));
    if (mCursor.moveToFirst()) {
        do {
            item = new RSSItem();
            item.setId(mCursor.getInt(mCursor
                    .getColumnIndex(DBAdaptor.RSSITEM_FIELD_ID)));
            item.setContent(mCursor.getString(mCursor
                    .getColumnIndex(DBAdaptor.RSSITEM_FIELD_CONTENT)));
            item.setDescription(mCursor.getString(mCursor
                    .getColumnIndex(DBAdaptor.RSSITEM_FIELD_DESCRIPTION)));
            item.setImage(mCursor.getString(mCursor
                    .getColumnIndex(DBAdaptor.RSSITEM_FIELD_IMAGE)));
            item.setPubdate(Common.changeFormatDate(mCursor.getString(mCursor
                    .getColumnIndex(DBAdaptor.RSSITEM_FIELD_PUBDATE))));
            item.setLink(mCursor.getString(mCursor
                    .getColumnIndex(DBAdaptor.RSSITEM_FIELD_LINK)));
            item.setRead(Integer.parseInt(mCursor.getString(mCursor
                    .getColumnIndex(DBAdaptor.RSSITEM_FIELD_READ))));
            item.setTitle(mCursor.getString(mCursor
                    .getColumnIndex(DBAdaptor.RSSITEM_FIELD_TITLE)));
            arrayrssitems.add(item);
            // do what ever you want here
        } while (mCursor.moveToNext());
    }
    mCursor.close();

问题是数据库中应该有项目,但是当代码到达if时(mCursor.movetofirst()它只是向右跳过关闭,而不是在if块中执行代码。

语法是否正确?

我最简单的方法是检查sqlite数据库中是否有内容?

这是getChannel Mathod。

public Cursor getChannel(String link){
    return db.query(DBAdaptor.CHANNELS_TABLE, 
            new String[] {
                            CHANNEL_FIELD_ID, 
                            CHANNEL_FIELD_TITLE, 
                            CHANNEL_FIELD_LINK,
                            CHANNEL_FIELD_DESCRIPTION,
                            CHANNEL_FIELD_LASTUPDATED
                         }, 
            CHANNEL_FIELD_LINK + " = '" + link + "'",
            null,null,null,null);
}


public long insertChannel(RSSChannel channel){
    ContentValues values = new ContentValues();
    values.put(CHANNEL_FIELD_TITLE,channel.getTitle());
    values.put(CHANNEL_FIELD_LINK,channel.getLink());
    values.put(CHANNEL_FIELD_DESCRIPTION,channel.getDescription());
    values.put(CHANNEL_FIELD_LASTUPDATED,channel.getLastupdated());
    return db.insert(DBAdaptor.CHANNELS_TABLE, null, values);
}
public 

0 个答案:

没有答案