【发布时间】:2017-05-31 13:32:15
【问题描述】:
我正在尝试从另一个类中的 Arraylist 中检索值,在我拥有的第一个类中:
public ArrayList<HashMap<String, String>> getListaCategorias() {
return listaCategorias;
}
现在在我的另一个类中,我试图获取 ArrayList 中的值并将它们插入到 TextView 中:
TodasAsCategorias todasAsCategorias = new TodasAsCategorias();
todasAsCategorias.getListaCategorias();
TextView txtDesignacao = (TextView)convertView.findViewById(R.id.Designacao);
txtDesignacao.setText("Values from the ArrayList");
问题是从 ArrayList 中获取值并将它们插入到 TextView 中,想法是有一个 ListView,其中每个值都指向一个项目(txtDesignacao 是位于 list_item 内的 TextView),我不能真正使用 SimpleAdapter,因为我的 ListView 作为一些特殊属性,这就是我使用 CustomAdapter 的原因
编辑
我将 arraylist 声明为静态,但现在我有一个错误:
TodasAsCategorias todasAsCategorias = array.get(i);
ArrayList<HashMap<String, String>> array = TodasAsCategorias.getListaCategorias();
TodasAsCategorias todasAsCategorias = array.get(i);
TextView txtDesignacao = (TextView) convertView.findViewById(R.id.Designacao);
txtDesignacao.setText("Values from the ArrayList");
说不兼容的类型,需要类TodasAsCategorias,找到HashMap
【问题讨论】:
-
一个选项是静态变量或方法
-
你想从一个 ArrayList 中设置一个文本组件?
-
@davidxxx 是的,这正是我想要的
标签: java android arraylist custom-adapter