【发布时间】:2015-03-16 09:59:23
【问题描述】:
`公共类 CategoryListAdapter 扩展 BaseAdapter {
private Context context;
ViewHolder holder;
private ArrayList<String> categoryNamesList, categoryIdList;
private final static int selectorsArray[] = { R.drawable.telecom_seletor, R.drawable.airlines_seletor, R.drawable.banking_seletor, R.drawable.dth_selector, R.drawable.electronics_seletor, R.drawable.health_seletor, R.drawable.holidays_seletor, R.drawable.insurance_seletor, R.drawable.shopping_web_seletor, R.drawable.taxi_seletor, R.drawable.food_seletor };
public CategoryListAdapter(Context context, ArrayList<String> categoryNamesList, ArrayList<String> categoryIdList) {
this.context = context;
this.categoryNamesList = categoryNamesList;
this.categoryIdList = categoryIdList;
}
@Override
public int getCount() {
return categoryNamesList.size();
}
@Override
public Object getItem(int position) {
return categoryNamesList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.category_item, null);
holder = new ViewHolder();
holder.title = (TextView) convertView.findViewById(R.id.title);
holder.icon = (ImageView) convertView.findViewById(R.id.img_title);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.title.setText(categoryNamesList.get(position));
holder.icon.setBackgroundResource(selectorsArray[position % selectorsArray.length]);
return convertView;
}
} `我使用图像作为图标和文本作为它们的标签,但是当我使用长文本并向下滚动然后向上滚动时,图像图标将被裁剪。 任何建议的家伙。请帮忙。
https://drive.google.com/file/d/0B_2CFh5suxS4bm83OVFqNHRLa1U/view?usp=sharing
https://drive.google.com/file/d/0B_2CFh5suxS4MHdJVktMVkpwXzg/view?usp=sharing
问题图片的链接
【问题讨论】:
-
用代码 sn-p 解释你的问题
-
请稍等..我会添加截图..
标签: android gridview android-custom-view custom-adapter