簡體   English   中英

自定義listview中TextView android錯誤的資源ID

[英]resource ID for a TextView android error in 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;
        }
    }

當我運行該應用程序時,出現以下錯誤:“您必須提供TextView的資源ID”。 我認為我必須從列表布局(listeventos.xml [1])中傳遞一些textview ID,但是我不知道該怎么做。 有人可以幫我嗎?

[1] http://pastebin.com/B1kgptHx

謝謝

解決更改為:

        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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM