当输入的文本不在 Android 自动完成列表中时,AutoCompleteText 出错
我正在使用 AutoCompleteText 来搜索将连接到数据库的位置并显示结果。当输入的文本是自动完成列表中的内容时,一切正常。但是,当我尝试输入数据库中不可用的不同文本时,应用程序将强制关闭。 这是我的代码
DataSPBU helper = new DataSPBU(this);
database = helper.getWritableDatabase();
Cursor dbCursor = database.query(TABLE_NAME, new String[] {SPBU, Alamat, JenisBensin, FasilitasUmum}, Alamat + "=?",new String[] {lokasi}, null, null, null);
if(dbCursor.moveToPosition(0)) {
String namaSpbu = dbCursor.getString(0);
String alamatSpbu = dbCursor.getString(1);
String jenisSpbu = dbCursor.getString(2);
String fasilitasSpbu = dbCursor.getString(3);
namaSpbuEdit.setText(namaSpbu);
alamatEdit.setText(alamatSpbu);
jenisBensinEdit.setText(jenisSpbu);
fasilitasEdit.setText(fasilitasSpbu);
}
else {
notFoundDialog = new AlertDialog.Builder(this)
.setTitle("RESULT NOT FOUND")
.setMessage("Hasil Tidak Ditemukan")
.setNegativeButton("close", new AlertDialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.create();
notFoundDialog.show();
}
//
任何帮助将不胜感激。
I'm using an AutoCompleteText for searching a location which would be connected to the database and the result would be shown. everything works fine when the inputed text is what is on the autocomplete list. But when i tried to input with a different text, which isnt available on the database, the application will get a force close.
here is my code
DataSPBU helper = new DataSPBU(this);
database = helper.getWritableDatabase();
Cursor dbCursor = database.query(TABLE_NAME, new String[] {SPBU, Alamat, JenisBensin, FasilitasUmum}, Alamat + "=?",new String[] {lokasi}, null, null, null);
if(dbCursor.moveToPosition(0)) {
String namaSpbu = dbCursor.getString(0);
String alamatSpbu = dbCursor.getString(1);
String jenisSpbu = dbCursor.getString(2);
String fasilitasSpbu = dbCursor.getString(3);
namaSpbuEdit.setText(namaSpbu);
alamatEdit.setText(alamatSpbu);
jenisBensinEdit.setText(jenisSpbu);
fasilitasEdit.setText(fasilitasSpbu);
}
else {
notFoundDialog = new AlertDialog.Builder(this)
.setTitle("RESULT NOT FOUND")
.setMessage("Hasil Tidak Ditemukan")
.setNegativeButton("close", new AlertDialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.create();
notFoundDialog.show();
}
//
any help would be highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嘿伙计,当您输入新文本时,在获取数据后首先输入数据库,
那么应用程序不会强制关闭。并且数据也会显示在自动完成文本视图中
code::
将数据与您的资源绑定后
Hey man when ever you enter a new text first enter into database after fetch the data,
then the application does not force close .and the data also shown in autocomplete text view
code::
after bind the data with your resource