ListView默记

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zsp_android_com/article/details/80689113

适配器

private int selectPosition = -1;

public void setSelectPosition(int selectPosition) {
    this.selectPosition = selectPosition;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder;
    if (convertView == null) {
        convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.service_type_item, parent, false);
        viewHolder = new ViewHolder();
        viewHolder.tvServiceType = convertView.findViewById(R.id.tvServiceType);
        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }
    viewHolder.tvServiceType.setText(dataBeans.get(position).getDicItem());
    // 选否
    if (selectPosition == position) {
        viewHolder.tvServiceType.setBackgroundResource(R.drawable.blue_button_en_c);
        viewHolder.tvServiceType.setTextColor(ContextCompat.getColor(context, R.color.background));
    } else {
        viewHolder.tvServiceType.setBackgroundResource(R.drawable.blue_button_nu_c);
        viewHolder.tvServiceType.setTextColor(ContextCompat.getColor(context, R.color.colorPrimary));
    }
    return convertView;
}

主代码

serTypeFirAdapter.setSelectPosition(editPosition);
serTypeFirAdapter.notifyDataSetChanged();
阅读更多 登录后自动展开
想对作者说点什么? 我来说一句
相关热词

没有更多推荐了,返回首页