【发布时间】:2015-10-27 00:58:18
【问题描述】:
所以伙计们,在我的项目中,我使用的是自定义 listView,起初我只传递给适配器字符串,但现在我想传递类,因为我想传递更多信息。但我不知道为什么它不会让我! 这是我的带字符串的适配器:
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一样正确扩展
标签: java android arraylist android-arrayadapter