即時通訊在數據庫中的一些消息,我從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