この問題の回避策を見つけました。スピナーの代わりに、テキストボックス(ウィットスピナースタイル)を使用し、それをアラートダイアログと組み合わせてリストを作成しました。多分それは最善の解決策ではありませんが、それは私にとってはうまくいきました:)))
public class SpinnerItem {
String spinnerText;
String value;
public SpinnerItem(String text, String value) {
this.spinnerText = text;
this.value = value;
}
public String getSpinnerText() {
return spinnerText;
}
public String getValue() {
return value;
}
public String toString() {
return spinnerText;
}
public class SearchProductActivity extends BaseActivity {
private EditText txtSearch;
private ListView listProducts;
private Button btnShoppingCart;
private EditText txtSelectFinancier;
private DevRestHelper rest;
private ListOfProducts adapter;
public static String financierRelationNumber;
private int numberOfItemsInBasket = 0;
private List<ProductModel> products = new ArrayList<ProductModel>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_product);
initControls();
getProjectSupplier();
financierRelationNumber = String.valueOf(OrderData.Financiers.get(0).RelationNumber);
txtSelectFinancier.setText(String.valueOf(OrderData.Financiers.get(0).Name));
GetProducts(financierRelationNumber);
setButtonActions();
ShoppingCart.ProductOwnerId = getProjectSupplier().get(0).getValue();
ShoppingCart.ProductOwner = getProjectSupplier().get(0).getSpinnerText();
}
private void initControls() {
btnShoppingCart = (Button) findViewById(R.id.activity_search_product_btnShoppingCart);
listProducts = (ListView) findViewById(R.id.activity_search_product_listProducts);
txtSearch = (EditText) findViewById(R.id.activity_search_product_txtName);
txtSelectFinancier = (EditText) findViewById(R.id.activity_search_product_txtFinancier);
}
private void setButtonActions() {
txtSelectFinancier.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!ShoppingCart.isEmpty()) {
AlertDialog.Builder dialog = new AlertDialog.Builder(SearchProductActivity.this);
dialog.setMessage(getString(R.string.err_selecting_new_finacier_will_empty_your_basket)).setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
listDialog(SearchProductActivity.this, "", getProjectSupplier(), txtSelectFinancier);
listProducts.setAdapter(null);
ShoppingCart.emptyCartItems();
ShoppingCart.ProductOwner = txtSelectFinancier.getText().toString();
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog alert = dialog.show();
TextView messageView = (TextView) alert.findViewById(android.R.id.message);
messageView.setGravity(Gravity.CENTER);
} else
listDialog(SearchProductActivity.this, "", getProjectSupplier(), txtSelectFinancier);
}
});
}
private List<SpinnerItem> getProjectSupplier() {
List<SpinnerItem> items = new ArrayList<SpinnerItem>();
for (DetermineFinanciersModel finaciers : OrderData.Financiers) {
items.add(new SpinnerItem(finaciers.Name, String.valueOf(finaciers.RelationNumber)));
}
return items;
}
private void listDialog(Context context, String title, final List<SpinnerItem> list, final TextView control) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(title);
List<String> strings = new ArrayList<String>();
for (SpinnerItem spinnerItem : list) {
strings.add(spinnerItem.getSpinnerText());
}
final CharSequence[] items = strings.toArray(new String[strings.size()]);
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int selectedItem) {
control.setText(list.get(selectedItem).getSpinnerText());
ShoppingCart.ProductOwnerId = list.get(selectedItem).getValue();
GetProducts(list.get(selectedItem).getValue());
}
});
AlertDialog alert = builder.create();
alert.show();
}
}