首页 > 其他 > 详细

自定义GrildView实现单选功能

时间:2014-11-14 23:58:48      阅读:528      评论:0      收藏:0      [点我收藏+]

首先看实现功能截图,这是一个自定义Dialog,并且里面内容由GrildView 绑定数据源,实现类似单选功能。

bubuko.com,布布扣

首先自定义Dialog,绑定数据源

bubuko.com,布布扣

自定义Dialog弹出框大小方法

bubuko.com,布布扣

最主要实现的就是点击颜色切换的功能,默认GrildView的每一项都是蓝色背景,当点击时候切换成红色。这里缓存了一个view,每次点击给这个view重新赋值,改变颜色

bubuko.com,布布扣

数据源Adapter代码:

public class ZheKouAdapter extends BaseAdapter {

  private Context context;
  private List<ZheKouMuBan> ZheKouList;
  protected LayoutInflater mLayoutInflater;

  public ZheKouAdapter(Context context, List<ZheKouMuBan> ZheKouList) {
    this.context = context;
    this.ZheKouList = ZheKouList;
    mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  }

  @Override
  public int getCount() {
    // TODO Auto-generated method stub
    return ZheKouList.size();
  }

  @Override
  public Object getItem(int position) {
    // TODO Auto-generated method stub
    return ZheKouList.get(position);
  }

  @Override
  public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    View view = convertView;
    if (view == null) {
      view = mLayoutInflater.inflate(R.layout.mul_desk_select, null);
      TextView txtname = (TextView)view.findViewById(R.id.mul_deskname);
      ZheKouMuBan zkmb = ZheKouList.get(position);
      txtname.setText(zkmb.ZKMB_Name);
      txtname.setTextColor(Color.WHITE);
      txtname.setGravity(Gravity.CENTER);
    }
    return view;
  }
}

 

自定义GrildView实现单选功能

原文:http://www.cnblogs.com/LIANQQ/p/4098330.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!