Android - Spinner没有显示所有结果

时间:2011-10-21 19:38:20

标签: android spinner android-spinner

我做了一个微调器,我填充了它。

微调:

package it.gogle.com;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;

public class Cars{ 

public static final String ALL_CARS = "All cars";

public static final String CAR = "CAR";

public static final String NAME = "NAME";

public static final String NAME1 = "NAME1";

public static final String NAME2 = "NAME2";

public static final String NAME3 = "NAME3";

public static final String CATEGORY = "CATEGORY";

private String car;

private String name;

private String name1;

private String name2;

private String name3;

private String category;

public Cars(String car, String name, String name1, String name2, String name3, String category){
    super();
    this.car = car;
    this.name = name;
    this.name1 = name1;
    this.name2 = name2;
    this.name3 = name3;
    this.category = category;}



public String getCar(){
    return car;}

public String getName(){
    return name;}

public String getName1(){
    return name1;}

public String getName2(){
    return name2;}

public String getName3(){
    return name3;}

public String getCategory(){
    return category;}

public static final Cars[] DB = new Cars[]{ 
 new Cars("BMW","X1","X3",X5","X6","SUV"),
 new Cars("AUDI","A1","Q7","A2","A5","OTHERS"),
 new Cars("BMW1","X3","X1",X6","X5","SUV"),
 new Cars("AUDI1","A2","Q7","A1","A5","OTHERS"),
 new Cars("BMW2","X6","X5",X3","X1","SUV"),
    };


private static ArrayList<String> names;

public static List<Map<String, String>> getData(){
    List<Map<String, String>> ret = new ArrayList<Map<String, String>>();
    for (Cars cars : DB){
        ret.add(cars.getMap());}
    return ret;}

public static List<Map<String, String>> getData(String name, String name1, String name2, String name3){
    List<Map<String, String>> ret = new ArrayList<Map<String, String>>();
    for (Cars cars : DB){
        //the error is here below I suppose
                    if (name.equals(ALL_CARS) || name.equals(cars.getName()))
        if (name1.equals(ALL_CARS) || name1.equals(cars.getName1()))
        if (name2.equals(ALL_CARS) || name2.equals(cars.getName2()))
                    if (name3.equals(ALL_CARS) || name3.equals(cars.getName3()))

         ret.add(cars.getMap());}
    return ret;}





Map<String, String> getMap(){
    HashMap<String, String> map = new HashMap<String, String>();

    map.put(CAR, car);
    map.put(NAME, name);
    map.put(NAME1, name1);
    map.put(NAME2, name2);
    map.put(NAME3, name3);
    map.put(CATEGORY, category);
    return map;}

public static ArrayList<String> getINames(){
    if (names == null){
        TreeSet<String> set = new TreeSet<String>();
        for (Cars cars : DB){set.add(cars.getName());}
        for (Cars cars : DB){set.add(cars.getName1());}
                    for (Cars cars : DB){set.add(cars.getName2());}
                    for (Cars cars : DB){set.add(cars.getName3());}

        names = new ArrayList<String>();
        names.addAll(set);}
    return names;}}

如果,在我的旋转器上,我点击“X1”它给我的结果是“宝马”而不是“BMW1”和“BMW2”,有时它只给我“BMW1”而不是其他两个。这取决于我如何更改我的代码。我希望看到包含我选择的所有结果,是否可能?我已经尝试过各种方式,但我不能做我想做的事情。我签署了我认为是问题的地方,也因为如果我改变那些行中​​的某些东西,那么改变也会产生结果。非常感谢你的帮助。

1 个答案:

答案 0 :(得分:0)

您缺少报价` new Cars("BMW2","X6","X5","X3","X1","SUV"),