データベースの値を使用して 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);
アプリケーションを実行すると、2 つのエントリが表示されます。これは正しいですが、正しいデータで表示されます。それは次のようなものを示しています
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
}
}
どこかで他の変更を加える必要がありますか。