我想在某个ID之后更新行,但我不确定如何。我从一个arraylist的最后一个位置获取了一个值,然后我将它传递给我的数据库助手。
private void addNewerOlderHashtags(List<Status> timeline)
{
// get the last id of the arraylist
int lastId = Integer.parseInt(timeline_arg.get(timeline_arg.size() -1).get("sql_id"));
for (int i=0; i < timeline.size(); i++){
long tweetId = Long.parseLong(timeline_arg.get(i).get("tweet_id"));
try {
Status status = mTwitter.showStatus(tweetId);
HashtagEntity[] entity = status.getHashtagEntities();
List<String> hashlist = new ArrayList<String>();
for (HashtagEntity hashtag : entity){
String text = hashtag.getText();
hashlist.add(text);
dbHelper.addNewerOlderHashtags(lastId, hashlist.toString());
}
} catch (TwitterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
数据库助手:
public void addNewerOlderHashtags(int id, String hashtags)
{
try {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(COL_HASHTAG_ENTITIES, hashtags);
String[] whereArgs = {Integer.toString(id)};
db.update(TABLE_TWEETS, values, Tweets.COL_ROW_ID + ">?", whereArgs);
db.close();
}
catch (Exception ex)
{
System.out.println(ex);
}
}