我做了一個微調,我已經填充它。Android - 微調不顯示所有結果
微調:
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 「但不是其他兩個。這取決於我如何更改我的代碼。我希望看到包含我選擇的所有結果,有可能嗎?我嘗試了各種方式,但我無法做我想做的事。我在我認爲是問題的地方簽了名,也是因爲如果我改變了這一行的內容,也會改變結果。非常感謝您的幫助。
你缺少一個報價'新車( 「BMW2」, 「X6」, 「X5」, 「X3」, 「X1」, 「SUV」),' – CamelSlack