如何在列表视图中显示表的所有记录?

时间:2015-09-05 10:52:44

标签: android

这是我的查询类,它有方法getuserEvents(),我希望在另一个类中显示我的表的所有记录,但是我遇到的问题只给了我第一条记录。

public ArrayList<String> getUserEvents() {
    ArrayList<String> EventsList = new ArrayList<String>();
    Cursor c = this.database.rawQuery("select FEventId, FEventName, FEventDescription, FEventStatus, FEventReligion, FromDate, ToDate from tblApEvents", new String[]{} );
    if (c.moveToFirst()) {
        do {
            EventsList.add(c.getString(0));
            EventsList.add(c.getString(1));
            EventsList.add(c.getString(2));
            EventsList.add(c.getString(3));
            EventsList.add(c.getString(4));
            EventsList.add(c.getString(5));
            EventsList.add(c.getString(6));
        } while (c.moveToNext());
    }
    return EventsList;
}

    QueryClass qc = new QueryClass(getApplication());
    qc.open();
    EventsList=qc.getUserEvents();

    if (!EventsList.equals("")) {

        id.add(EventsList.get(0));
        EventName.add(EventsList.get(1));
        EDescription.add(EventsList.get(2));
        EStatus.add(EventsList.get(3));
        EReligion.add(EventsList.get(4));
        EventTDate.add(EventsList.get(7));
        qc.close();

    }

1 个答案:

答案 0 :(得分:1)

你的方法应如下所示:

 public ArrayList<Event> getUserEvents() {
        ArrayList<Event> EventsList = new ArrayList<>();
        Cursor c = this.database.rawQuery("select FEventId, FEventName, FEventDescription, FEventStatus, FEventReligion, FromDate, ToDate from tblApEvents", new String[]{} );
        if (c.moveToFirst()) {
            do {
                EventsList.add(new Event(c.getString(0),c.getString(1),c.getString(2),c.getString(3),c.getString(4),c.getString(5),c.getString(6)));
            } while (c.moveToNext());
        }
        return EventsList;
    }

你的Event课程:

class Event{

private String FEventId;
private String FEventName;
    // other members
    //parameterized constructor
    // setter and getter

}

最后创建custom adapter并填充Event

中的listview数据