gpt4 book ai didi

Android - CustomAdapter 不获取对象

转载 作者:行者123 更新时间:2023-11-30 01:49:43 24 4
gpt4 key购买 nike

我创建了一个自定义适配器以将我的元素发送到我的适配器类。

我的项目:

  public ItemAcompanhe(String dataPar, String cabecalhoPar, String descricaoPar, int imagePar){
this.data = dataPar;
this.cabecalho = cabecalhoPar;
this.descricao = descricaoPar;
this.image = imagePar;
}

我的适配器

 public AdapterAcompanheSantana(Context context, int resource, ArrayList<ItemAcompanhe> objects/*, String[] objects2*/) {
//super(context, resource, objects);
super(context, resource, objects);
}

我设置 itens 的适配器:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v=((Activity)getContext()).getLayoutInflater().inflate(R.layout.item_list_acompanhe,null);

ItemAcompanhe holder = null;
holder = new ItemAcompanhe(jsonItemAcompanhe);

// ImageView item_acompanhe_btn_topo
ImageView img = (ImageView) v.findViewById(R.id.item_acompanhe_btn_topo);
img.setBackgroundResource(image[position]);

// TextView item_acompanhe_txt_cabecalho CABECALHO DESCRICAO
TextView textViewTituloAgendaFragItem = (TextView) v.findViewById(R.id.item_acompanhe_txt_cabecalho);
textViewTituloAgendaFragItem.setText(listaDeCabecalhos[position]);

// TextView item_acompanhe_txt_data
TextView textViewDatasAgendaFragItem = (TextView) v.findViewById(R.id.item_acompanhe_txt_data);
textViewDatasAgendaFragItem.setText(listaDeDatas[position]);

// TextView item_acompanhe_txt_conteudo
TextView textViewDescricaoAgendaFragItem = (TextView) v.findViewById(R.id.item_acompanhe_txt_conteudo);
textViewDescricaoAgendaFragItem.setText(listaDeDescricao[position]);

Typeface font = Typeface.createFromAsset(getContext().getAssets(), "fonts/OpenSans-Regular.ttf");
textViewDescricaoAgendaFragItem.setTypeface(font);



return v;
}

我无法从我的列表中获取任何项目,并将其设置为适配器中的参数。任何人都知道我是如何解决这个问题的?

最佳答案

这个

ItemAcompanhe holder = null;
holder = new ItemAcompanhe(jsonItemAcompanhe);

应替换为

ItemAcompanhe holder = getItem(position);

这将从数据集中获取一个项目(在您的情况下由父类(super class)处理)。我建议您避免在每次调用 getView 时都膨胀一个新的 convertView,但只有当 convertView 为 null 时

 if (convertView == null) {     
convertView = ((Activity)getContext()).getLayoutInflater().inflate(R.layout.item_list_acompanhe,null);
}

并返回convertView

关于Android - CustomAdapter<MyClass> 不获取对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33245086/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com