У меня есть этот код и по какой-то причине я не могу заставить его работать?
Может кто-нибудь увидеть проблему?
Мне нужны эти данные, чтобы иметь возможность возвращать все записи, содержащие одно и то же имя, введенное в текстовое поле mNameSearchDelete. однако никакие записи не возвращаются, которые должны быть там.
спасибо
protected void searchForNameToDelete() {
carryOutNameSearch(mNameSearchDelete, mListFormDelete);
}
private void carryOutNameSearch(TextBox theInputScreen, Form theOutputForm) {
listOfIDs = new Vector(); // save IDs of records in case we want to delete
theOutputForm.deleteAll(); // clear the form
try {
RecordStore rs = RecordStore.openRecordStore("EventsDatabase", true);
// Use the inner class so that the enumeration only gives
// us those records with a matching name.
RecordEnumeration re = rs.enumerateRecords(new NameMatcher(theInputScreen.getString()), null, false);
while (re.hasNextElement()) {
int id = re.nextRecordId();
listOfIDs.addElement(new Integer(id));
byte [] recordBuffer = rs.getRecord(id);
String record = new String(recordBuffer);
// extract the name and the age from the record
int endOfnameEvent = record.indexOf(";");
int endOfdescEvent = record.indexOf(";", endOfnameEvent + 1);
String name = record.substring(0, endOfnameEvent);
String desc = record.substring(endOfnameEvent + 1, endOfdescEvent);
theOutputForm.append(name + " description: " + desc + "\n");
}
rs.closeRecordStore();
}
catch(Exception e){
// mAlertConfirmDetailsSaved.setString("Couldn't read details");
System.err.println("Error accessing database");
}
Display.setCurrent(theOutputForm);
}
/* An inner class to allow us to select only
* those records with a matching name.
*/
static class NameMatcher implements RecordFilter {
String nameToMatch;
public NameMatcher(String nameEvent) {
nameToMatch = nameEvent;
}
public boolean matches(byte[] record) {
if (record.length < nameToMatch.length()) {
return false;
}
String strRecord = new String(record);
if (strRecord.startsWith(nameToMatch)) {
return true;
}
return false;
}
}