0
我對每個產品都有微調框。微調有產品選擇(如重量10磅,20磅等) 也有二級選項,如顏色。微調框setOnItemSelectedListener不啓動
爲此,我想讓客戶在將顏色綁定到同一個微調器後選擇第一個重量。但我不能讓快速啓動setOnItemSelectedListener。
謝謝你的時間!
ddlOptions = (Spinner) lnr.findViewById(R.id.ddlOptions);
ddlOptions.setId(products.get(i).ID);
SpinnerBind(ddlOptions, products.get(i).ID, -1);
ddlOptions.setOnItemSelectedListener(new OnItemSelectedListener() {
int first = 0;
int ProductId = ddlOptions.getId();
@Override
public void onItemSelected(AdapterView <? > parentView, View selectedItemView, int position, long id) {
if (first != 0) {
SpinnerBind(ddlOptions, ProductId, mItems.get(position).getId());
} else first = 1;
}
@Override
public void onNothingSelected(AdapterView <? > parentView) {
// your code here
}
});
public static class Element {
private String mText;
private int mId;
public Element(String text, int id) {
mText = text;
mId = id;
}
public int getId() {
return mId;
}
public void setId(int id) {
mId = id;
}
public String getmText() {
return mText;
}
public void setmText(String mText) {
this.mText = mText;
}
@Override
public String toString() {
return mText;
}
}
private List <Element> mItems;
public void SpinnerBind(Spinner ddlOptions, int ProductId, int ParentId) {
mItems = new ArrayList <MainScreen.Element>();
ArrayList <String> optionNames = new ArrayList <String>();
ArrayList <ProductOption> productOptions = this.dhn.GetProductOptions(ProductId, ParentId);
for (int i = 0; i < productOptions.size(); i++) {
mItems.add(new Element(productOptions.get(i).OptionName, productOptions.get(i).ID));
}
ArrayAdapter <MainScreen.Element> adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, android.R.id.text1, mItems);
ddlOptions.setAdapter(adapter);
}
我覺得我的適配器有問題,微調不認爲我選擇了一些東西。 – Mert