我正在尝试 listView 和 listAdaptor 使用数据库值填充屏幕。我的列表没有正确显示。下面是我的 DataBaseHandler 类的代码
public List<Notifications> getNotificationList() {
List<Notifications> notificationList = new ArrayList<Notifications>();
String selectQuery = "SELECT * FROM " + TABLE_CONTACTS;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
Notifications objN = cursorToNotifications(cursor);
notificationList.add(objN);
} while (cursor.moveToNext());
}
// return contact list
return notificationList;
}
这是我如何打印调用上述函数的值
ArrayAdapter<Notifications> adapter = new ArrayAdapter<Notifications>(this,
android.R.layout.simple_list_item_1, objN);
setListAdapter(adapter);
当我运行应用程序时,它显示两个输入,这是正确的,但显示正确的数据。它显示类似
com.example.appname@41448fa0
com.example.appname@41449278
有人可以指出我哪里出错了。谢谢
抱歉,Android 世界的新手。你的意思是添加
@Override
public String toString() {
return "something useful"; // define this
}
在我的通知类中,就像
public class Notifications {
//private variables
String _type;
String _message;
String _id;
// Empty constructor
public Notifications() {}
// constructor
public Notifications(String type, String message, String id){
this._type = type;
this._message = message;
this._id = id;
}
// getting ID
public String getId(){
return this._id;
}
public void setId(String id){
this._id = id;
}
public String getType(){
return this._type;
}
// setting id
public void setType(String type){
this._type = type;
}
// getting name
public String getMessage(){
return this._message;
}
// setting name
public void setMessage(String message){
this._message = message;
}
@Override
public String toString() {
return "something useful"; // define this
}
}
抱歉,Android 世界的新手。你的意思是添加
@Override
public String toString() {
return "something useful"; // define this
}
在我的通知类中,就像
public class Notifications {
//private variables
String _type;
String _message;
String _id;
// Empty constructor
public Notifications(){
}
// constructor
public Notifications(String type, String message, String id){
this._type = type;
this._message = message;
this._id = id;
}
// getting ID
public String getId(){
return this._id;
}
public void setId(String id){
this._id = id;
}
public String getType(){
return this._type;
}
// setting id
public void setType(String type){
this._type = type;
}
// getting name
public String getMessage(){
return this._message;
}
// setting name
public void setMessage(String message){
this._message = message;
}
@Override
public String toString() {
return "something useful"; // define this
}
}
我是否需要在任何地方进行任何其他更改。