Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 自定义listview中TextView android错误的资源ID_Java_Android_Listview_Adapter - Fatal编程技术网

Java 自定义listview中TextView android错误的资源ID

Java 自定义listview中TextView android错误的资源ID,java,android,listview,adapter,Java,Android,Listview,Adapter,我有一个自定义列表视图: 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 = lo

我有一个自定义列表视图:

    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;
        }
    }
公共类事件{
公共字符串名称;
公共字符串本地;
公共字符串inicio;
公共事件(字符串nome、字符串local、字符串inicio){
this.nome=nome;
this.local=本地;
this.ini=ini;
}
公共字符串getNome(){
返回nome;
}
公共无效集合名称(字符串名称){
this.nome=nome;
}
公共字符串getLocal(){
返回本地;
}
公共void setLocal(字符串本地){
this.local=本地;
}
公共字符串getInicio(){
返回inicio;
}
公共无效设置inicio(字符串inicio){
this.ini=ini;
}
}
公共类AdapterEventos扩展了ArrayAdapter{
私人最终语境;
私人最终ArrayList事件ArrayList;
公共适配器事件(上下文、ArrayList事件){
super(context、R.layout.listeventos、eventos);
this.context=上下文;
this.eventosArrayList=eventos;
}
公共视图getViewEventos(int位置、视图转换视图、视图组父级){
//制造充气机
LayoutFlater充气器=(LayoutFlater)context.getSystemService(context.LAYOUT\u充气器\u服务);
//从充气机获取rowView
视图LINHAEVENTOVERVIEW=充气机。充气(R.layout.listeventos,父项,false);
//从行视图中获取文本视图
TextView nomeView=(TextView)LinhaEventoView.findViewById(R.id.tvNomeEvento);
TextView localView=(TextView)LinhaEventoView.findViewById(R.id.tvLocalEvento);
TextView-inicioView=(TextView)LinhaEventoView.findViewById(R.id.tvInicioEvento);
//设置textView的文本
nomeView.setText(eventosArrayList.get(position.getNome());
localView.setText(eventosArrayList.get(position.getLocal());
setText(eventosArrayList.get(position.getInicio());
//返回行视图
返回LinhaEventoView;
}
}
当我运行应用程序时,出现以下错误:“您必须为TextView提供资源ID”。我想我必须从列表布局(listeventos.xml[1])中传递一些textview id,但我不知道如何做到这一点。有人能帮我吗

[1]


感谢

解决了以下问题:

        public AdapterEventos(Context context, ArrayList<Evento> eventos) {

            super(context, R.layout.listeventos,R.id.tvNomeEvento, eventos);
            this.context = context;
            this.eventosArrayList = eventos;
        }
公共适配器事件(上下文、ArrayList事件){
super(context,R.layout.listeventos,R.id.tvNomeEvento,eventos);
this.context=上下文;
this.eventosArrayList=eventos;
}