即时通讯在数据库中的一些消息,我从rss.My的问题是,我想新的饲料覆盖旧的one.I要每次有10个新闻在我的数据库,但?现在即时通讯有我每次刷新10更多的时间..如何更新时更新我的数据库
搜索网,我发现该解决方案必须是onUpgrade
method.Could你帮我做的,这是onUpgrade使用IM象现在
public void onUpgrade (SQLiteDatabase db,int oldVersion, int newVersion){
android.util.Log.w("Constants",
"Upgrading database, which will destroy all data");
db.execSQL("DROP TABLE IF EXISTS myDB");
onCreate(db);
}
编辑
public void createEntry(String string,String string2,String string3,String string4,String string5){
ContentValues cv=new ContentValues();
cv.put(DBHelper.TITLE, string);
cv.put(DBHelper.AGONISTIKI, string2);
cv.put(DBHelper.SKOR, string3);
cv.put(DBHelper.GIPEDO, string4);
cv.put(DBHelper.DATE, string5);
try
{
ourDatabase.insert("osfpDB",null,cv);
}
catch(Exception e)
{
Log.e("DB ERROR ON .INSERT", e.toString()); // prints the error message to the log
e.printStackTrace(); // prints the stack trace to the log
}
}
public void update(String string,String string2,String string3,String string4,String string5){
ContentValues cv=new ContentValues();
cv.put(DBHelper.TITLE, string);
cv.put(DBHelper.AGONISTIKI, string2);
cv.put(DBHelper.SKOR, string3);
cv.put(DBHelper.GIPEDO, string4);
cv.put(DBHelper.DATE, string5);
try
{
ourDatabase.update("osfpDB",cv,DBHelper.ROWID,null);
}
catch(Exception e)
{
Log.e("DB ERROR ON .UPDATE", e.toString()); // prints the error message to the log
e.printStackTrace(); // prints the stack trace to the log
}
}
0123当你的应用程序和数据库的用户更新版本和处理来自旧的数据库版本的数据移植到新的
和
ArrayList<HashMap<String, String>> List_agones = new ArrayList<HashMap<String, String>>(messages.size());
for (Message2 msg : messages){
des.add(msg.getDescription());//keimeno
SK.add(msg.getskor());
GOALA.add(msg.getgoal1());
GOALB.add(msg.getgoal2());
TITLES.add(msg.getTitle());
AGONISTIKI.add(msg.getagonistiki());
HashMap<String, String> map = new HashMap<String, String>();
map.put("agon", msg.getagonistiki());
map.put("name", msg.getTitle());
map.put("date", msg.getDate());
map.put("gip", msg.getgipedo());
map.put("SK", msg.getskor());
List_agones.add(map);
ListAdapter mSchedule = new SimpleAdapter(this, List_agones, R.layout.agonesrow,
new String[] {"agon","name", "date","gip", "SK"}, new int[] {R.id.TextView00,R.id.TextView01, R.id.TextView02, R.id.TextView04, R.id.TextView03});
this.setListAdapter(mSchedule);
//grafei stin vasi dedomenwn
//-------------------------
HotOrNot entry=new HotOrNot(agones.this);
entry.open();
if(map== null){
Toast.makeText(agones.this, "1",
Toast.LENGTH_SHORT).show();
entry.createEntry(msg.getTitle(),msg.getagonistiki(),msg.getskor(),msg.getgipedo(),msg.getDate());
}else{
Toast.makeText(agones.this, "2",
Toast.LENGTH_SHORT).show();
entry.update(msg.getTitle(),msg.getagonistiki(),msg.getskor(),msg.getgipedo(),msg.getDate());
}
entry.close();
//----------------------------------------
我已经尝试过你的链接,但我已经堆放在某个地方。我们可以聊天吗? –
你可以发布失败的代码吗?不知道什么时候可以进行聊天,但我会尽可能尝试。 – Chris