爲什麼這個光標:sqlite的光標設置錯列
Objects object = new Objects(cursor.getString(0),cursor.getString(1),
cursor.getString(2),cursor.getString(3));
我有這樣的結果:
Objects{id=1, name='http://www.escmobile.com/projects/android/okhttp/saul.jpg', url='null', type='null'
但選擇的結果是這樣的
TYPE=IMAGES NAME=Image1 URL=http://www.escmobile.com/projects/android/okhttp/saul.jpg
這種方式我插入數據
void addObjects(Objects object) {
SQLiteDatabase db = this.getWritableDatabase();
onCreate(db);
ContentValues values = new ContentValues();
//values.put(OBJECT_ID,object.getId()); // OBJECT Name
values.put(OBJECT_NAME, object.getName()); // OBJECT Name
values.put(OBJECT_URL, object.getUrl()); // OBJECT URL
values.put(OBJECT_TYPE, object.getType()); // Contact type
System.out.println(values);
// Inserting Row
long id = db.insert(TABLE_OBJECTS, null, values);
System.out.println("id:"+id);
db.insert(TABLE_OBJECTS, null, values);
db.close(); // Closing database connection
}
//從主要活動
DatabaseHandler db = new DatabaseHandler(getApplicationContext());
Log.d("Insert: ", "Inserting ..");
db.addObjects(new Objects("Image1", "http://www.escmobile.com/projects/android/okhttp/saul.jpg", "IMAGES", "Leb Funny"));
db.addObjects(new Objects("Image1", "http://www.escmobile.com/projects/android/okhttp/saul.jpg","IMAGES","Leb Funny"));
db.addObjects(new Objects("Image1", "http://www.escmobile.com/projects/android/okhttp/saul.jpg", "IMAGES", "Leb Funny"));
List<Objects> Objects = db.getAllObjects();
Log.d("hehe","tttttt");
System.out.println(Objects);
DBadapter adapter = new DBadapter(getApplicationContext(), R.layout.grid_item_layout, Objects);
這個Object類
public Objects(String name, String url,String type,String category) {
//this.id=id;
this.name = name;
this.url = url;
this.type = type;
this.category =category;
}
public Objects()
{
}
public int getId()
{
return id;
}
public String getName()
{
return name;
}
public String getUrl()
{
return url;
}
public String getType()
{
return type;
}
public String getCategory()
{
return category;
}
public void setId(int id)
{
this.id=id;
}
public void setName(String name)
{
this.name=name;
}
public void setUrl(String url)
{
this.name=url;
}
public void setcategory(String category)
{
this.category=category;
}
}
你爲什麼不使用'SimpleCursorAdapter'? – pskink
@pskink用途我使用自定義適配器,我會閱讀更多關於這個。 – Moudiz