我有一个绑定视图Holder的自定义适配器。
public void onBindViewHolder(RecyclerView.ViewHolder holder, int section, int relativePosition, int absolutePosition) {
ArrayList<String> itemsInSection = allData.get(section).getAllItemsInSection();
String itemName = itemsInSection.get(relativePosition);
ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
itemViewHolder.itemTitle.setText(itemName);
// Try to put a image . for sample i set background color in xml layout file
// itemViewHolder.itemImage.setBackgroundColor(Color.parseColor("#01579b"));
}
当我尝试将itemsInSection
替换为我的要求时,我得到一个错误,指出无法在行String itemName = itemsInSection.get(relativePosition);
中解析.get(int)
如何解决它。
预期代码:
public void onBindViewHolder(RecyclerView.ViewHolder holder, int section, int relativePosition, int absolutePosition) {
String itemsInSection = allData.get(section).getAllItemsInSection();
String itemName = itemsInSection.get(relativePosition); //Error here
ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
itemViewHolder.itemTitle.setText(itemName);
// Try to put a image . for sample i set background color in xml layout file
// itemViewHolder.itemImage.setBackgroundColor(Color.parseColor("#01579b"));
}