gpt4 book ai didi

java - 如何修改BaseAdapter中的资源?

转载 作者:行者123 更新时间:2023-12-01 10:07:44 26 4
gpt4 key购买 nike

我有客户适配器:

public class AdapterListGroups extends BaseAdapter {

private List<ItemMusicGroup> listItemsMusicGroup;
private LayoutInflater layoutInflater;
final private String division = " ";

public AdapterListGroups(Context context, List<ItemMusicGroup> listItemsMusicGroup) {
this.listItemsMusicGroup = listItemsMusicGroup;
this.layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public int getCount() {
return this.listItemsMusicGroup.size();
}

@Override
public Object getItem(int position) {
return this.listItemsMusicGroup.get(position);
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if ( view == null ) {
view = layoutInflater.inflate(R.layout.list_item, parent, false);
}
setContentItem(view, position);
return view;
}

private void setContentItem(View view, int position)
{
ImageView imageView = (ImageView) view.findViewById(R.id.item_imageView_icon);
imageView.setImageResource(R.drawable.asses);

ItemMusicGroup currentItemMusicGroup = getItemMusicGroup(position);

TextView nameGroup = (TextView) view.findViewById(R.id.item_textView_nameGroup);
nameGroup.setText(currentItemMusicGroup.getName());

if ( currentItemMusicGroup.getCountAlbum() != null ) {
TextView countAlbum = (TextView) view.findViewById(R.id.list_item_textView_countAlbum);
countAlbum.setText(currentItemMusicGroup.getCountAlbum() + this.division + R.string.list_item_textView_countSing);
}


}

public ItemMusicGroup getItemMusicGroup(int position) {
return (ItemMusicGroup) getItem(position);
}
}

该行:

countAlbum.setText(currentItemMusicGroup.getCountAlbum() + this.division + R.string.list_item_textView_countSing);

我想在此类中使用我自己的文本 + 字符串的 const 自定义 countAlbum TextView 的文本(函数 getString(id) 不起作用)。

这里我得到了自己的文本+ int(idResourse)。

我怎样才能做到呢?谢谢!

最佳答案

您需要使用getResources().getString(R.string.example)

尝试:

countAlbum.setText(currentItemMusicGroup.getCountAlbum() + this.division + countAlbum.getContext().getResources().getString(R.string.list_item_textView_countSing));

关于java - 如何修改BaseAdapter中的资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36332787/

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