2

我想列出记录存储中的所有记录。我已经宣布了一个清单:

Private List tlist = new List("Select One", List.IMPLICIT);

还列举了记录:

Form mainf;
Command exit = new Command("Exit", Command.EXIT, 0);
RecordEnumeration re = null;
int numrecords = 0;
    try {
        re = contactList.enumerateRecords(null, null, false);
        numrecords = re.numRecords();
    } catch (RecordStoreException rse ) { numrecords = 0;}

现在我只需要知道如何列出列表中的所有记录。

4

2 回答 2

3

添加RecordintoVector并使用循环将Vector值附加到List. 请参阅下面的示例代码,

RecordStore s =  RecordStore.openRecordStore(recordStoreName, true);
RecordEnumeration e = s.enumerateRecords(null, null, false);
Vector vector = new Vector();
while(e.hasNextElement()) {
  vector.addElement(new String(e.nextRecord()));
}
List l = new List(null, CENTER);
for (int i = 0; i < vector.size(); i++) {
  l.append(vector.elementAt(i).toString(), null); 
}
于 2011-11-02T10:12:52.557 回答
1

您可以使用以下代码,

public String [] getRecordData()
{
    String[] str = null;
    int counter = 0;
    try 
    {
        RecordEnumeration enumeration = rs.enumerateRecords(null, null, false);
        str = new String[rs.getNumRecords()];

        while(enumeration.hasNextElement())
        {
            try 
            {
                str[counter] = (new String(enumeration.nextRecord()));
                counter ++;
            } 
            catch (Exception e) 
            {
                e.printStackTrace();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return str;
}
于 2011-11-03T07:18:54.800 回答