首页 > 移动平台 > 详细

android 级联菜单

时间:2015-03-24 21:06:37      阅读:285      评论:0      收藏:0      [点我收藏+]
android listview级联三菜单选择地区,本地数据库sqlite级联地区,item选中不变色

 

适配器  核心代码如下:

public class ListAdapter extends BaseAdapter {
    private Context context;
    private List<item> myList;
    private LayoutInflater mInflater;
    private int selectedPosition = -1;// 选中的位置
    public ListAdapter(Context context, List<item> myList,int selected) {
        this.context = context;
        this.myList = myList;
        this.mInflater = LayoutInflater.from(this.context);
        selectedPosition=selected;
    }
 
    public int getCount() {
        return myList.size();
    }
 
    public Object getItem(int position) {
        return myList.get(position);
    }
 
    public long getItemId(int position) {
        return position;
    }
    public void setSelectedPosition(int position) {
        selectedPosition = position;
    }
 
    public View getView(final int position,  View convertView, final ViewGroup parent) {
         
         ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.block_list_item, null);
 
            convertView.setTag(holder);
        else {
            holder = (ViewHolder) convertView.getTag();
        }
        final View cView=convertView;
        final ViewHolder cHolder=holder;
        holder.iLayout=(LinearLayout) convertView.findViewById(R.id.ll_root);
        holder.name = (TextView) convertView.findViewById(R.id.tv_name);
        holder.img = (ImageView) convertView.findViewById(R.id.iv_right);
        holder.name.setText(myList.get(position).getName());
        System.out.println(Item值为:+selectedPosition);
        System.out.println(自带的为:+position);
        if (selectedPosition == position) {
            holder.iLayout.setSelected(true);
            holder.iLayout.setPressed(true);
            holder.iLayout.setBackgroundColor(Color.RED);
        else {
            holder.iLayout.setSelected(false);
            holder.iLayout.setPressed(false);
            holder.iLayout.setBackgroundColor(Color.TRANSPARENT);  
 
        }
 
        return convertView;
    }
     
    class ButtonView {
        int layoutViewId;
 
        ButtonView(int tId) {
            layoutViewId = tId;
        }
    }
      
 
    public final class ViewHolder {
        public TextView name;
        public ImageView img;
        public LinearLayout iLayout;
    }
 
}
 
参考:http://www.2cto.com/kf/201407/321095.html
 
                                
 


 

android 级联菜单

原文:http://www.cnblogs.com/feng666/p/4363849.html

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