Я надеюсь, что вы, ребята, можете помочь решить мою проблему.
Моя проблема не в том, чтобы получить кратное значение столбца. В моей базе содержится 4 столбца (id, namaStation, ticket, masa). прямо сейчас программа отображает только значение namaStation. Это может произойти из-за метода toString () в классе Comment, потому что он возвращает только 1 значение (namaStation). может мне помочь ??
Это моя программа. ##
1. Позвоните по запросу.
`public void onClick (Просмотреть представление) {
@SuppressWarnings("unchecked")
ArrayAdapter<Comment> adapter = (ArrayAdapter<Comment>) getListAdapter();
Comment comment = null;
switch (view.getId()) {
case R.id.add:
List<Comment> values = datasource.query("Kelana Jaya");
adapter = new ArrayAdapter<Comment>(this, android.R.layout.simple_list_item_1, values);
setListAdapter(adapter);
break;`
2. Запрос.
@SuppressWarnings("static-access")
public List<Comment> query(String namaStation){
//List<Comment> comments = new ArrayList<Comment>();
database = dbHelper.getReadableDatabase();
List<Comment> comments = new ArrayList<Comment>();
Cursor cursor = database.query(MySQLiteHelper.TABLE_COMMENTS,
allColumns, MySQLiteHelper.COLUMN_namaStation+"=?",new String[]{namaStation}, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
// Comment comment = cursorToComment(cursor);
Comment comment = new Comment();
comment.setId(cursor.getLong(0));
comment.setNamaStation(cursor.getString(1));
comments.add(comment);
comment.setTicket(cursor.getString(2));
comments.add(comment);
cursor.moveToNext();
}
// Make sure to close the cursor
cursor.close();
return comments;
3. Класс комментариев
public class Comment {
private long id;
public String namaStation;
public String ticket;
public String masa;
public String comment;
public int x;
public Comment(){
}
public Comment(long id, String namaStation, String ticket, String masa){
this.id=id;
this.namaStation=namaStation;
this.ticket=ticket;
this.masa=masa;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getNamaStation() {
return namaStation;
}
public void setNamaStation(String comment) {
this.namaStation = comment;
}
public String getTicket() {
return ticket;
}
public void setTicket(String comment) {
this.ticket = comment;
}
public String getMasa() {
return masa;
}
public void setMasa(String comment) {
this.masa= comment;
}
// Will be used by the ArrayAdapter in the ListView
public String toString() {
return ticket;
}
}
Дисплей (макет не в порядке, потому что я еще не настроил его .. :))
дисплей