所以大家好,在我的項目中我使用自定義listView,起初我只傳遞給適配器String的,但現在我想傳遞類的,因爲我想傳遞更多的信息。但我不是爲什麼它不會讓我! 這裏是我的適配器字符串尚未:ArrayAdapter與類
class costum_adapter extends ArrayAdapter<String>{
public costum_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;
}
}
現在,我想,以獲得類的,我只需要改變的說法,這裏是ArrayList的horarios我會改變的ArrayList horarios。 「horario」是我的課程,在這裏:
public class horario{
public String hora;
public int destino;
public int note;
public horario(String horaIn, int Destino, int Nota){
hora = horaIn;
destino = Destino;
note = Nota;
}
}
我也在使用ArrayList。但是我用類中的對象填充了ArrayList。 當我嘗試更改適配器上的參數以接收我的類時,它無法識別它,我開始鍵入「horario」但它不被識別,我不知道爲什麼,因爲我在其他文件中有該類。
您是否注意到您的構造函數中存在拼寫錯誤? costum_adapter而不是custom_adapter。 –
是的,我知道,那是因爲當我創建java文件時,我發現它錯了,然後我不得不聲明所有與costum_adapter,否則會給錯誤。 –
請確保你的擴展正確做公共類擴展ArrayAdapter –