我正在爲公交車站創建應用程序,以提供時間表。爲此,我使用自定義列表視圖。那就是:自定義ListView - 自定義參數
class custom_adapter extends ArrayAdapter<String>{
public custom_adapter(Context context, ArrayList<String> horarios) {
super(context, R.layout.costum_listview ,horarios);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater horarioInflater = LayoutInflater.from(getContext());
View costumView = horarioInflater.inflate(R.layout.costum_listview, parent, false);
String singleHorario = getItem(position);
TextView hora = (TextView) costumView.findViewById(R.id.Hora);
TextView nota = (TextView) costumView.findViewById(R.id.Nota);
hora.setText(singleHorario);
nota.setText(" ");
return costumView;
}
}
現在你可以看到我剛剛2 texViews然而,「霍拉」是顯示總線的定時器,在「諾塔」是一些筆記,就像有一天公共汽車不去或者類似的東西一樣。而我的問題正是在於「nota」textview。我有幾十個arrayList傳遞給這個自定義的ListView,以及幾十個和幾十個定時器,並且有一些定時器需要放置一個便條,其他的我不需要。所以,我可以給這個自定義ListView另外一個參數,就像一個布爾值或者其他東西,所以我可以在該代碼中做一個if/else來爲每一個添加一個註釋。爲了做到這一點,我需要改變什麼?我一直在努力,但並沒有完全做到這一點。
但問題是,如果我必須傳遞一個類,那麼這個類將不得不擁有ArrayList,但是我想放入的「nota」不是對所有Array的單個註釋,而是一個註釋, (或不)在數組的每一個項目中。不知道我能否更好地解釋。如果我要放一個音符,我傳遞的數組中的每一項都將被檢查。 –