我有过滤类别类型->类别->产品的要求。为此,我必须像在eclipse package explorer中一样使用嵌套微调器。
我怎样才能做到?

最佳答案

听着,我不确定你是不是在找这样的东西。我有两个微调器,当用户从brand spinner中选择一个项目时,modelspinner与该品牌的所有产品一起设置。

private Spinner brandSpinner;
private Spinner modelSpinner;

brandSpinner = (Spinner)root.findViewById(R.id.brand_spinner);
modelSpinner = (Spinner)root.findViewById(R.id.model_spinner);


brandsAdapter = new ArrayAdapter<BrandItem>(mContext, android.R.layout.simple_spinner_dropdown_item, ArrayListWithBrands);

//I am not sure if it is needed:
brandsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

brandSpinner.setAdapter(brandsAdapter);

brandSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> a, View v, int pos, long id) {

        //Harcoding Brands:
        BrandItem brand = brandsArrHarcode.get(pos);

        final ArrayList<String> modelsArr = brand.getModels();

        modelsAdapter = new CustomArrayAdapter(mContext, android.R.layout.simple_spinner_dropdown_item, modelsArr);

        modelsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        modelSpinner.setAdapter(modelsAdapter);

        modelSpinner.setSelection(modelsAdapter.getPosition(camera.getModel()));
    }

    @Override
    public void onNothingSelected(AdapterView<?> a) {}
}

);

希望能有所帮助。

10-07 20:57