更新:
嗨,我正在使用AlertDialog.Builder
中的下拉列表(spinner)来显示可选项。但是当未点击时,spinner
仅显示String array
的第一项。如果点击,则会强制关闭。我的代码如下。
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater li=LayoutInflater.from(this);
View v=li.inflate(R.layout.searchme, null);
builder.setIcon(android.R.drawable.ic_input_get);
builder.setView(v);
builder.setTitle("Search");
LayoutInflater factory = LayoutInflater.from(getApplicationContext());
final View textEntryView = factory.inflate(R.layout.searchme, null);
builder.setView(textEntryView);
Spinner spin=(Spinner)textEntryView.findViewById(R.id.searchspinner);
Utilities.ManageDeptSpinner(this, spin);
for(int i=0;i<spin.getCount();i++)
{
long id=spin.getItemIdAtPosition(i);
spin.setSelection(i, true);
break;
}
spin.setOnItemSelectedListener(new MyOnItemSelectedListener());
builder.setPositiveButton("Go",new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
try
{
titletext = (EditText) textEntryView.findViewById(R.id.titleText1);
persontext = (EditText) textEntryView.findViewById(R.id.personText2);
prioritytext = (EditText) textEntryView.findViewById(R.id.priorityText3);
title_text = titletext.getText().toString();
person_text = persontext.getText().toString();
priority_text = prioritytext.getText().toString();
String condition = "titlee='"+title_text+"' or pname ='"+person_text+"' or prior='"+priority_text+"'";
refresh_data(" ASC","prior",condition);
}
catch(Exception e)
{
e.printStackTrace();
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
}
}});
builder.setNegativeButton("Cancel",new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
dialog.cancel();
// Do nothing
}
});
AlertDialog alert = builder.create();
alert.show();
MyOnItemSelectedListener.java:
public class MyOnItemSelectedListener implements OnItemSelectedListener
{
@SuppressWarnings("unused")
public void onItemSelected(AdapterView<?> parent,View view, int pos, long id)
{
try
{
switch(parent.getId())
{
case R.id.searchspinner:
Toast.makeText(getApplicationContext(),"\n Selected : "+parent.getItemAtPosition(pos).toString()+"\n",Toast.LENGTH_LONG).show();
break;
}
}catch(Exception e)
{
e.printStackTrace();
}
}
public void onNothingSelected(AdapterView<?> parent)
{
// Do nothing.
}
}
我正在收到以下异常:
我正在收到以下异常:
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
我的输出:
如果我点击这个旋转器,会出现强制关闭。
任何帮助都将不胜感激,谢谢!