我已经能够将值检索到我的表单中。这些值在保存按钮单击时插入到表中,同时也被检索到同一个表单中(在同一个保存单击上)。但现在的问题是每个单击值以连续流的形式显示。我想在上次单击后清除屏幕(从表单中刷新值)并仅显示最新的表状态值。这是我正在处理的代码:
public void fieldChanged(Field field, int context) //respond to button events
{
if (field == showInputButton) //if first button selected
{
Dialog.alert(TextField1.getText()); //show text from first input field
try
{
//Open or create the database
Database db = DatabaseFactory.openOrCreate("database1.db");
//Insert Data from db
Statement statement1 = db.createStatement("INSERT INTO DirectoryItems(category_id,name,phone,email) VALUES ('1','"+TextField1.getText()+"','"+TextField2.getText()+"','"+TextField3.getText()+"')");
statement1.prepare();
statement1.execute();
statement1.close();
//Retrieve data
try
{
add(new RichTextField("Attempting to retrieve data from " +
"database1.db on the SDCard."));
Statement st = db.createStatement("SELECT name FROM DirectoryItems");
st.prepare();
Cursor c = st.getCursor();
Row r;
int i = 0;
while(c.next())
{
r = c.getRow();
i++;
add(new RichTextField(i + "Name = " + r.getString(0)));
}
if (i==0)
{
add(new RichTextField("No data in the DirectoryItems table."));
}
st.close();
db.close();
}
catch( Exception e )
{
System.out.println( e.getMessage() );
e.printStackTrace();
}
}
有谁知道这个。请指教。