我正在尝试制作一个带有微调器的 alertdialog.builder 。微调器项目最初是从数据库中填充的。这是我的代码的一部分:
update.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
final View update_layout = getLayoutInflater().inflate(R.layout.update_layout, null);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setView(update_layout);
builder.setTitle("Update existing DB");
builder.setPositiveButton("ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which)
{
spinner = (Spinner) update_layout.findViewById(R.id.spinner1);
List<String> arrayspin=new ArrayList<String>();
Cursor csr1 = db.rawQuery("SELECT name FROM sqlite_master WHERE type='table'", null);
int count = csr1.getCount();
csr1.moveToFirst();
for (int m=0; m>count; m++){
if (csr1.getString(csr1.getColumnIndex("name"))!="android_metadata")
{
String cont = csr1.getString(csr1.getColumnIndex("name"));
arrayspin.add(cont);
}
csr1.moveToNext();
}
ArrayAdapter adp = new ArrayAdapter(MainActivity.this,android.R.layout.simple_spinner_item,arrayspin);
adp.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adp);
table2 = spinner.getSelectedItem().toString();
editText2 = (EditText) update_layout.findViewById(R.id.editText2);
new Updating().execute();
}
});
builder.setNegativeButton("back",new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog,int which)
{
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
它没有给我任何错误,但在应用程序中,微调器没有显示任何项目。然后我尝试修改代码,只是为了测试微调器,如下所示:
update.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
final View update_layout = getLayoutInflater().inflate(R.layout.update_layout, null);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setView(update_layout);
builder.setTitle("Update existing DB");
builder.setPositiveButton("ok", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog,int which)
{
spinner = (Spinner) update_layout.findViewById(R.id.spinner1);
String[] items = { "this", "is", "a", "really","really2", "really3",
"really4", "really5", "silly", "list" };
ArrayAdapter adp = new ArrayAdapter(MainActivity.this,android.R.layout.simple_spinner_item,items);
adp.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adp);
table2 = spinner.getSelectedItem().toString();
editText2 = (EditText) update_layout.findViewById(R.id.editText2);
new Updating().execute();
}
});
builder.setNegativeButton("back",new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog,int which)
{
dialog.dismiss();
}});
AlertDialog alert = builder.create();
alert.show();
}});
但微调器仍然没有显示任何项目。我做错了什么?