我有一个简单的对话框,带有一个EditText
和一个Spinner
...... Spinner 只有两个项目,位于对话框的底部......
使用下拉模式时,下拉列表中仅显示一项,如果我使用对话框模式,则显示所有项目...
有谁知道解决方案?
这是我的简单布局 - 如果我删除它就不能正常工作android:spinnerMode="dialog"
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="@+id/etInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<Spinner
android:id="@+id/spItems"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dialog" />
</LinearLayout>
这是对话框代码,没有什么特别的......
public PromptAndSpinnerDialog(Context context, int title, int message, String text, int selectedIndex, Integer[] items, int okButtonID)
{
super(context);
theContext = context;
setTitle(title);
if (message > 0)
setMessage(message);
init(text, selectedIndex, items, okButtonID);
}
public PromptAndSpinnerDialog(Context context, int title, String message, String text, int selectedIndex, Integer[] items, int okButtonID)
{
super(context);
theContext = context;
setTitle(title);
setMessage(message);
init(text, selectedIndex, items, okButtonID);
}
private void init(String text, int selectedIndex, Integer[] items, int okButtonID)
{
View v = LayoutInflater.inflate(getContext(), R.layout.dialog_prompt_and_spinner);
setView(v);
setPositiveButton(okButtonID, this);
setNegativeButton(R.string.cancel, this);
getReferences(v);
etInput.setText(text);
etInput.selectAll();
String[] strings = new String[items.length];
for (int i = 0; i < items.length; i++)
strings[i] = theContext.getString(items[i]);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(theContext, R.layout.sherlock_spinner_item, strings);
adapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
spItems.setAdapter(adapter);
if (selectedIndex != -1)
spItems.setSelection(selectedIndex);
}