ArrayAdapter class
ArrayAdapter with class
伙计们,在我的项目中,我使用的是自定义 listView,起初我只传递给适配器字符串,但现在我想传递 class,因为我想传递更多信息。但我不明白为什么它不会让我!
这是我的带有字符串的适配器:
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;
}
}
现在,我认为为了接收 class,我只需要更改参数,我会将 ArrayList horarios 更改为 ArrayList horarios。 "horario" 是我的 class,这里:
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。但是我用 class 中的对象填充了 ArrayList。
当我尝试更改适配器上的参数以接收我的 class 时,它无法识别它,我开始输入 "horario" 但它无法识别,我不知道为什么,因为我有 class 在另一个文件中。
这样试试:
class costum_adapter extends ArrayAdapter<horario> {
public costum_adapter(Context context, ArrayList<horario> horarios) {
super(context, R.layout.costum_listview ,horarios);
}
试试这个
public costum_adapter(Context context, ArrayList<horario> 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).getHora();
String singlenote = getItem(position).getNote();
TextView hora = (TextView) costumView.findViewById(R.id.Hora);
TextView nota = (TextView) costumView.findViewById(R.id.Nota);
hora.setText(singleHorario);
nota.setText(singlenote);
return costumView;
}
型号Class
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;
}
public String getHora() {
return hora;
}
public void setHora(String hora) {
this.hora = hora;
}
public int getDestino() {
return destino;
}
public void setDestino(int destino) {
this.destino = destino;
}
public int getNote() {
return note;
}
public void setNote(int note) {
this.note = note;
}
}
所以我设法解决了我自己的问题。我的问题是我无法将 "ArrayList" 更改为 "ArrayList",horario 是我想要的 class,但那是因为 "horario" 是在更大的 class 中声明的。所以我只需要更改为 "ArrayList","mostraHorario" 更大 class。
伙计们,在我的项目中,我使用的是自定义 listView,起初我只传递给适配器字符串,但现在我想传递 class,因为我想传递更多信息。但我不明白为什么它不会让我! 这是我的带有字符串的适配器:
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;
}
}
现在,我认为为了接收 class,我只需要更改参数,我会将 ArrayList horarios 更改为 ArrayList horarios。 "horario" 是我的 class,这里:
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。但是我用 class 中的对象填充了 ArrayList。 当我尝试更改适配器上的参数以接收我的 class 时,它无法识别它,我开始输入 "horario" 但它无法识别,我不知道为什么,因为我有 class 在另一个文件中。
这样试试:
class costum_adapter extends ArrayAdapter<horario> {
public costum_adapter(Context context, ArrayList<horario> horarios) {
super(context, R.layout.costum_listview ,horarios);
}
试试这个
public costum_adapter(Context context, ArrayList<horario> 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).getHora();
String singlenote = getItem(position).getNote();
TextView hora = (TextView) costumView.findViewById(R.id.Hora);
TextView nota = (TextView) costumView.findViewById(R.id.Nota);
hora.setText(singleHorario);
nota.setText(singlenote);
return costumView;
}
型号Class
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;
}
public String getHora() {
return hora;
}
public void setHora(String hora) {
this.hora = hora;
}
public int getDestino() {
return destino;
}
public void setDestino(int destino) {
this.destino = destino;
}
public int getNote() {
return note;
}
public void setNote(int note) {
this.note = note;
}
}
所以我设法解决了我自己的问题。我的问题是我无法将 "ArrayList" 更改为 "ArrayList",horario 是我想要的 class,但那是因为 "horario" 是在更大的 class 中声明的。所以我只需要更改为 "ArrayList","mostraHorario" 更大 class。