我想列出记录存储中的所有记录。我已经宣布了一个清单:
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;}
现在我只需要知道如何列出列表中的所有记录。
答案 0 :(得分:3)
将Record
添加到Vector
并使用该循环将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);
}
答案 1 :(得分: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;
}