Android 创建对象以表示数据库';s表
我正在开发一个Android应用程序 我想知道是否真的有必要从SQLite数据库创建表示表的对象 我正在实现insert方法,并为表使用特定对象,也许我可以使用HashMap。此Hashmap将是该方法的参数Android 创建对象以表示数据库';s表,android,sqlite,Android,Sqlite,我正在开发一个Android应用程序 我想知道是否真的有必要从SQLite数据库创建表示表的对象 我正在实现insert方法,并为表使用特定对象,也许我可以使用HashMap。此Hashmap将是该方法的参数 public boolean insertEntry(HashMap entry) { ... String name = entry.get(Constants.COLUMN_NAME); ... } 您觉得怎么样?我也使用HashMap在db中表示数据对象,扩展表
public boolean insertEntry(HashMap entry) {
...
String name = entry.get(Constants.COLUMN_NAME);
...
}
您觉得怎么样?我也使用HashMap在db中表示数据对象,扩展表中的HashMap数据对象可能很容易阅读,例如:
public class TableObjectClass extends HashMap<String, String>{
/* Define column of table object here */
public static final String KEY_COLUMN_ID = "id"; /* ID of record */
public static final String KEY_COLUMN_OTHER = "version"; /* Define other column */
/* Define public method to set/get properties of table object, example */
public String getID(){
return this.get(KEY_COLUMN_ID);
}
public void setID(String strID){
this.put(KEY_COLUMN_ID, strID);
}
}
公共类TableObjectClass扩展HashMap{
/*在此定义表对象的列*/
公共静态最终字符串键\u列\u ID=“ID”/*记录的ID*/
公共静态最终字符串键\u COLUMN\u OTHER=“version”/*定义其他列*/
/*定义公共方法来设置/获取表对象的属性,例如*/
公共字符串getID(){
返回此.get(KEY\u COLUMN\u ID);
}
public void setID(String strID){
this.put(KEY\u COLUMN\u ID,strID);
}
}