私は製品詳細画面を持っているアプリケーションを作成しています。その画面では、設定可能なアイテムの長さに基づいて動的スピナーを作成しています。しかし、最初のダイナミックスピナー項目の選択に基づいて他のダイナミックスピナーのリストを変更しようとすると、フィルターされた配列がクリックされたスピナーリストに移動しますが、別のスピナーに追加する必要があります。これは私が本当にこの状況に固執している、私は多くを試みたが実装することができないので、私はあなたの助けを求めています。私は3を持っている色のスピナーの下スピナーアイテムの選択に基づいて特定の位置でダイナミックスピナーの新しいデータを設定します
- :
シナリオは私は2つのスピナー1を持っている特定の製品のためのを仮定すると、色属性のあるされ、他方はSize属性との両方は、例えば、相互に連結しているためであります色: - 私はホワイト、ブルー、グリーン 同様のサイズの下で: - S、M、L、XL
しかし、白い色のために、私は2つだけ、すなわちS使用可能なサイズとM を持っていますので、私は必要なものですユーザーがSpinneをクリックしたとき2番目のスピナーの配列は自動的にS、M、およびviseversaに変更されます
これらはダイナミックスピナーですべて実行しています。ここで
が私のコードです: -
private void showconfigurableProducts() {
try {
count = 0;
mllSpinner.setVisibility(View.VISIBLE);
for (int i = 0; i < lisProductDetail.get(0).getConfigurable()
.size(); i++) {
TextView tv = new TextView(getActivity());
tv.setText(lisProductDetail.get(0).getConfigurable().get(i)
.getLabel());
mllSpinner.addView(tv);
final Spinner spinner = new Spinner(getActivity());
spinner.setTag(i);
final ArrayAdapter<OptionProductDetailModel> arrayAdapter=new ArrayAdapter<OptionProductDetailModel>(
getActivity(),
android.R.layout.simple_spinner_dropdown_item,
lisProductDetail.get(0).getConfigurable().get(i)
.getOptions());
spinner.setAdapter(arrayAdapter);
spinner.setSelection(0, false);
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
private String attributeId;
@Override
public void onItemSelected(AdapterView<?> parent,
View view, int position, long id) {
OptionProductDetailModel option = (OptionProductDetailModel) spinner
.getSelectedItem();
List<OptionProductDetailModel> sizedataArray = new ArrayList<OptionProductDetailModel>();
sizedataArray.add(option);
if (listDummy.size() > 0) {
selectbtatrue = check(sizedataArray, listDummy);
}
if (selectbtatrue) {
return;
} else {
for (int i = 0; i < lisProductDetail.get(0)
.getConfigurable().size(); i++) {
for (int j = 0; j < lisProductDetail.get(0)
.getConfigurable().get(i).getOptions()
.size(); j++) {
if (lisProductDetail.get(0)
.getConfigurable().get(i)
.getOptions().get(j).getLabel() == option
.getLabel()) {
attributeId = lisProductDetail.get(0)
.getConfigurable().get(i)
.getId();
}
}
}
for (int i = 0; i < lisProductDetail.get(0)
.getConfigurable().size(); i++) {
if (attributeId != lisProductDetail.get(0)
.getConfigurable().get(i).getId()) {
// if (listDummy.size() > 0) {
// listDummy = new
// ArrayList<OptionProductDetailModel>();
// }
for (int k = 0; k < option.getProducts()
.size(); k++) {
for (int j = 0; j < lisProductDetail
.get(0).getConfigurable()
.get(i).getOptions().size(); j++) {
for (int l = 0; l < lisProductDetail
.get(0).getConfigurable()
.get(i).getOptions().get(j)
.getProducts().size(); l++) {
if (option
.getProducts()
.get(k)
.equals(lisProductDetail
.get(0)
.getConfigurable()
.get(i)
.getOptions()
.get(j)
.getProducts()
.get(l))) {
listDummy
.add(lisProductDetail
.get(0)
.getConfigurable()
.get(i)
.getOptions()
.get(j));
} else {
}
}
}
System.out.print(listDummy);
}
}
if (count < 2) {
int tag = (int) spinner.getTag();
if (tag == i) {
} else {
lisProductDetail.get(0)
.getConfigurable().get(i)
.setOptions(listDummy); // Here i am getting S,M,L but i do not know how to update in in Size Attribute Spinner.
}
count = count + 1;
}
}
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
mllSpinner.addView(spinner);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private boolean check(List<OptionProductDetailModel> SelectedArray,
List<OptionProductDetailModel> DummyArray) {
for (int i = 0; i < SelectedArray.size(); i++) {
for (int j = 0; j < DummyArray.size(); j++) {
if (SelectedArray.get(i).getId()
.equalsIgnoreCase(DummyArray.get(j).getId())) {
btatrue = true;
} else {
btatrue = false;
}
}
}
return btatrue;
}
私にあなたの提案を入力してください、あなたの助けは、私はダイナミックの場合には、それが実現可能であるかどうか、この問題に私の2日間無駄にされています を理解されるであろうスピナー。 ありがとうございました
説明が複雑すぎたり、複雑すぎるコードが多すぎます。あなたが望むものを簡略化してください! :) –
ちょっとジミット、私はちょうどスピナー項目のいずれかの選択に基づいてスピナーリストの項目を変更したい、条件はすべてのスピナーは動的です – sid
その後、メソッドを試してみてください。最初の 'onItemSelected'メソッドの' onItemSelected'メソッドの中に他のスピナーを入れ、 'onItemSelected'メソッドの中で次のスピナーなどを... !!! –