Android的 - 显示警告对话框空的ListView [英] Android - Display Alert Dialog for empty ListView
问题描述
如何显示空列表视图中的警告对话框时,有没有列表视图项目。请发现有三个文本框下面的图片。我有当有列表中没有记录/匹配的记录来实现空列表视图。
How to show the alert dialog for the empty list view when there are no listview items. Please find the below image having three text fields. I have to implement the empty list view when there are no records/unmatched records in the list.
列表视图实现如下:
ListView empListView;
empListView = (ListView)findViewById(R.id.list1 );
我要显示的empListView的警告对话框。请帮我与样品code /链接。
I have to show the alert dialog box for the empListView. Please help me with the samplecode/links.
推荐答案
这一切都取决于你如何实现setAdapter方法等,但这里有一个例子:
It all depends on how you implement the setAdapter method etc. But here is an example:
if(cdata.getCount()==0) {
//empty, show alertDialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Search is empty")
.setCancelable(true)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
}
else {
//Not empty, set the adapter or do what you want.
empListview.setAdapter(new MyCursorAdapter( getApplicationContext(), R.layout.listview, cdata, fields, names));
}
在code以上还没有经过测试。但要稍作调整工作,我可能会忘记一些东西。
The code above havent been tested. But should work with minor adjustments, I might have forgotten something.
这篇关于Android的 - 显示警告对话框空的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!