Spinner重复项错误

时间:2017-01-06 15:14:30

标签: android spinner

如何在微调器中删除重复数据,因为当我再次选择微调器时,它将显示重复的数据。有什么解决方案吗?

喜欢点击自行车时。它显示了其他旋转器上所有自行车的细节。 然后我再次从那个旋转器中选择自行车或其他物品。它再次显示自行车细节。包含自行车信息的其他微调器上的信息重复。

例如当我点击自行车它显示本田yamaha suzuki其他然后我再次点击自行车旋转器它将显示本田yamaha铃木其他本田yamaha suzuki其他。

    // Drop down layout style - list view with radio button


    ArrayAdapter<String> vehicle_type_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, vehicle_type);

    // Drop down layout style - list view with radio button
    vehicle_type_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    // attaching data adapter to spinner
    spinner.setAdapter(vehicle_type_adapter);

    ArrayAdapter<String> select_make_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, select_make);

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

    // attaching data adapter to spinner
    spinner1.setAdapter(select_make_adapter);
    ArrayAdapter<String> model_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, select_model);

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

    // attaching data adapter to spinner
    spinner4.setAdapter(model_adapter);
    ArrayAdapter<String> year_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, year);

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

    // attaching data adapter to spinner
    spinner3.setAdapter(year_adapter);


}


@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    // On selecting a spinner item
    String item = parent.getItemAtPosition(position).toString();
   // String item1=spinner1.getItemAtPosition(position).toString();

    if(item=="Bike")
    {



        select_make.add("Honda");
        select_make.add("suzuki");
        select_make.add("sohrab");
        select_make.add("Yamaha");
        select_make.add("Other");
        select_model.add("100cc");
        select_model.add("125cc");
        select_model.add("70cc");
        select_model.add("150cc");
        select_model.add("Other");
        int i = 2000;
        int j = 1;
        String vt;
        String yearr;
        year.add("Year");
        for (i = 2000; i <= 2017; i++) {
            yearr = String.valueOf(i);
            year.add(yearr);

        }

        ArrayAdapter<String> year_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, year);

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

        // attaching data adapter to spinner
        spinner3.setAdapter(year_adapter);
        ArrayAdapter<String> select_make_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, select_make);

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

        // attaching data adapter to spinner
        spinner1.setAdapter(select_make_adapter);
        ArrayAdapter<String> model_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, select_model);

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

        // attaching data adapter to spinner
        spinner4.setAdapter(model_adapter);
    }

//为微调器创建适配器

req.params.user 

1 个答案:

答案 0 :(得分:1)

只需编辑这样的代码,....

if(item=="Bike")
{  //clear other spinner array list
   select_make.clear();
   select_model.clear();
   year.clear();

    select_make.add("Honda");
    select_make.add("suzuki");
    select_make.add("sohrab");
    select_make.add("Yamaha");
    select_make.add("Other");
    select_model.add("100cc");
    select_model.add("125cc");
    select_model.add("70cc");
    select_model.add("150cc");
    select_model.add("Other");
    int i = 2000;
    int j = 1;
    String vt;
    String yearr;
    year.add("Year");
    for (i = 2000; i <= 2017; i++) {
        yearr = String.valueOf(i);
        year.add(yearr);

    }

之后为什么要再次分配适配器?..你不需要这样做......只需再停止编码......设置适配器一次就够了