我需要知道如何在没有意图服务的情况下将数据从活动页面传递到 dbhelper 类。我从服务器获取数据并将数据传递到数据库。我真的很困惑。
我以这种方式存储数据
public static HashMap<String, Object> listhashmap;
我将它传递给 dbhelper 类,我用过
listitems = FirstActivity.arraylistitems;
这是代码
public DBHelper(Context context) {
super(context, DBName, null, version);
currentContext = context;
newarraylistitems = FirstActivity.arraylistitems;
System.out.println("newarraylistitems="+newarraylistitems);
DBPath = "/data/data/" + context.getPackageName() + "/databases";
createDatabase();
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
private void createDatabase() {
boolean dbExists = checkDbExists();
/* ("ID" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE ,
"user_message_id" VARCHAR DEFAULT NA, "message" VARCHAR DEFAULT
NA, "title" VARCHAR DEFAULT NA, "message_time" VARCHAR DEFAULT NA, "mp3" VARCHAR DEFAULT NA,
"userID" VARCHAR DEFAULT NA)*/
if (dbExists) {
// do nothing
} else {
DB = currentContext.openOrCreateDatabase(DBName, 0, null);
DB.execSQL("CREATE TABLE IF NOT EXISTS " +tableName +" (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE, " +
"user_message_id VARCHAR DEFAULT NA," +"message VARCHAR DEFAULT NA," + "title VARCHAR DEFAULT NA)"+
"mp3 VARCHAR DEFAULT NA "+ "userID VARCHAR DEFAULT NA;");
////some dummy contents
DB.execSQL("INSERT INTO " +
tableName +
" Values ('M','Sing','India',25);");
DB.execSQL("INSERT INTO " +
tableName +
" Values ('C','Raje','India',25);");
DB.execSQL("INSERT INTO " +
tableName +
" Values ('D','Phonu','Argentina',20);");
DB.execSQL("INSERT INTO " +
tableName +
" Values ('V','Veera','EU',25);");
DB.execSQL("INSERT INTO " +
tableName +
" Values ('T','Shenoi','Bangla',25);");
DB.execSQL("INSERT INTO " +
tableName +
" Values ('L','Lamha','Australia',20);");
}
}
private boolean checkDbExists() {
SQLiteDatabase checkDB = null;
try {
String myPath = DBPath + DBName;
checkDB = SQLiteDatabase.openDatabase(myPath, null,
SQLiteDatabase.OPEN_READONLY);
} catch (SQLiteException e) {
// database does't exist yet.
}
if (checkDB != null) {
checkDB.close();
}
return checkDB != null ? true : false;
}
}
我已经为 listview 创建了基本适配器,有没有其他方法可以将活动页面的 hashmap 数据传递给 dbhelper 类这listitems
是hashmap
我在 dbhelper 类中创建的。
有人可以帮我吗@谢谢