GridView 的 getChildAt(postion) 无法获取指定位置项的解决方案(为选定状态动态设置指定项)
最编程
2024-07-18 10:18:36
...
public AllGVAdapterbylevel(List<Map<String, Object>> list, Context context,int location) {
this.list = list;
this.context = context;
this.pos=location;
inflater= LayoutInflater.from(context);
}
、、、、、、、
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder=null;
//加载item布局 将xml布局加载到内存中,形成一个view
if(convertView==null){ //被复用后的convertview类依然包含tag
holder=new ViewHolder();
convertView=inflater.inflate(R.layout.tequan_gridview_item,null);
holder.iv_huanyuan_zuo= (ImageView) convertView.findViewById(R.id.iv_huanyuan_zuo);
holder.zhishiyou= (ImageView) convertView.findViewById(R.id.zhishiyou);
holder.zhishiup= (ImageView) convertView.findViewById(R.id.zhishiup);
holder.iv_huanyuan_bg= (ImageView) convertView.findViewById(R.id.iv_huanyuan_bg);
holder.needjifent= (TextView) convertView.findViewById(R.id.needjifent);
if (position==0){
holder.zhishiyou.setVisibility(View.INVISIBLE);
// holder.zhishiup.setVisibility(View.VISIBLE);
// holder.needjifent.setTextColor(Color.parseColor("#da408a"));
// holder.iv_huanyuan_bg.setVisibility(View.VISIBLE);
}
if (position==pos){
// holder.zhishiyou.setVisibility(View.INVISIBLE);
holder.zhishiup.setVisibility(View.VISIBLE);
holder.needjifent.setTextColor(Color.parseColor("#da408a"));
holder.iv_huanyuan_bg.setVisibility(View.VISIBLE);
}
convertView.setTag(holder);
}else {//convertview不为空,不为空则说明convertview包含tag
holder= (ViewHolder) convertView.getTag();
}
Map<String,Object> map= (Map<String, Object>) getItem(position);
holder.iv_huanyuan_zuo.setImageResource((Integer) map.get("img"));
holder.needjifent.setText((String) map.get("txt"));
itemView=convertView;
return convertView;
}