我想过滤listView以获取多个数据,但我实际上并没有将数据存储在数组中。
直接从.csv文件中提取,如下所示:
public View getView(final int pos, View convertView, final ViewGroup parent){
TextView mView = (TextView)convertView;
if(null == mView){
mView = new TextView(parent.getContext());
mView.setTextSize(28);
}
mView.setText(getItem(pos).getItemName());
return mView;
}
private void loadArrayFromFile(){
try {
InputStream is = ctx.getAssets().open("menustat.csv");
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line;
//Read each line
while ((line = reader.readLine()) != null) {
//Split to separate the name from the capital
String[] RowData = line.split(",");
//Create a State object for this row's data.
mealList cur = new mealList();
cur.setResturant(RowData[0]);
cur.setFoodCategory(RowData[1]);
cur.setItemName(RowData[2]);
cur.setItemDescription(RowData[3]);
cur.setServingsPerItem(RowData[4]);
cur.setServingSize(RowData[5]);
cur.setServingSizeUnit(RowData[6]);
cur.setCalories(RowData[7]);
cur.setFat(RowData[8]);
cur.setSodium(RowData[9]);
cur.setCarbs(RowData[10]);
cur.setFiber(RowData[11]);
cur.setProtein(RowData[12]);
//Add the State object to the ArrayList (in this case we are the ArrayList).
this.add(cur);
}
} catch (IOException e) {
e.printStackTrace();
}
}
作为参考,我正在尝试这样做:Android - How to filter a listview on multiple values?