有些人可以给我一个示例,用于显示来自SQLite数据库的单个数据,并使用搜索框和搜索按钮将其显示在文本视图中。
我的问题是我想在数据库中搜索带有ID的数据,该ID将输入到搜索框,当我按下按钮时,它将在textview中显示一些信息。
答案 0 :(得分:0)
显示textview,您可以使用用户光标并使用:
if (database != null) {
Cursor cursor = database.query(YOURTABLE, null, null, null, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
textview.setText(cursor.getString(yourcolumn));
cursor.moveToNext();
}
cursor.close();
对于搜索框:( 0.5秒后自动搜索)或者您可以按钮选择按钮
editsearch.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
private Timer timer = new Timer();
private final long DELAY = 500; // in ms
@Override
public void afterTextChanged(Editable s) {
timer.cancel();
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
// TODO: do what you need here (refresh list)
// you will probably need to use runOnUiThread(Runnable action) for some specific actions
}
}, DELAY);
//Search data by Cursor
}
}
});
希望这有帮助!