[英]resource ID for a TextView android error in custom listview
I have this custom listview: 我有这个自定义列表视图:
public class Evento {
public String nome;
public String local;
public String inicio;
public Evento(String nome, String local, String inicio) {
this.nome = nome;
this.local = local;
this.inicio = inicio;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getLocal() {
return local;
}
public void setLocal(String local) {
this.local = local;
}
public String getInicio() {
return inicio;
}
public void setInicio(String inicio) {
this.inicio = inicio;
}
}
public class AdapterEventos extends ArrayAdapter<Evento> {
private final Context context;
private final ArrayList<Evento> eventosArrayList;
public AdapterEventos(Context context, ArrayList<Evento> eventos) {
super(context, R.layout.listeventos, eventos);
this.context = context;
this.eventosArrayList = eventos;
}
public View getViewEventos(int position, View convertView, ViewGroup parent) {
//Create inflater
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//Get rowView from inflater
View LinhaEventoView = inflater.inflate(R.layout.listeventos, parent, false);
//Get the text view from the rowView
TextView nomeView = (TextView) LinhaEventoView.findViewById(R.id.tvNomeEvento);
TextView localView = (TextView) LinhaEventoView.findViewById(R.id.tvLocalEvento);
TextView inicioView = (TextView) LinhaEventoView.findViewById(R.id.tvInicioEvento);
//Set the text for textView
nomeView.setText(eventosArrayList.get(position).getNome());
localView.setText(eventosArrayList.get(position).getLocal());
inicioView.setText(eventosArrayList.get(position).getInicio());
//return rowView
return LinhaEventoView;
}
}
When I run the app I got the following error: 'You must supply a resource ID for a TextView'. 当我运行该应用程序时,出现以下错误:“您必须提供TextView的资源ID”。 I think i have to pass some textview id from list layout (listeventos.xml [1]) but i doesn't know how to do that. 我认为我必须从列表布局(listeventos.xml [1])中传递一些textview ID,但是我不知道该怎么做。 Can somebody help me with that? 有人可以帮我吗?
[1] http://pastebin.com/B1kgptHx [1] http://pastebin.com/B1kgptHx
Thanks 谢谢
Resolved changing to this: 解决更改为:
public AdapterEventos(Context context, ArrayList<Evento> eventos) {
super(context, R.layout.listeventos,R.id.tvNomeEvento, eventos);
this.context = context;
this.eventosArrayList = eventos;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.