zoukankan      html  css  js  c++  java
  • Android单选中listview中的一项

    public class LipsListAdapter extends BaseAdapter {
        private Context context;
        private List<Lips> lipsList;
        private Handler handler;
        private int checkedPosition = -1;// 记录被选择的项
    
        public LipsListAdapter(Context context, List<Lips> lipsList, Handler handler) {
            this.context = context;
            this.lipsList = lipsList;
            this.handler = handler;
        }
    
        @Override
        public int getCount() {
            return lipsList.size();
        }
    
        @Override
        public Object getItem(int position) {
            return lipsList.get(position);
        }
    
        @Override
        public long getItemId(int position) {
            return position;
        }
    
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = LayoutInflater.from(context).inflate(R.layout.item_order_list, null);
            }
            final Lips lips = lipsList.get(position);
            TextView tv_matnr = (TextView) convertView.findViewById(R.id.tv_matnr);
            TextView tv_plan = (TextView) convertView.findViewById(R.id.tv_plan);
            TextView tv_out = (TextView) convertView.findViewById(R.id.tv_out);
            TextView tv_lgort = (TextView) convertView.findViewById(R.id.tv_lgort);
            CheckBox cb_chooseMatnor = (CheckBox) convertView.findViewById(R.id.cb_chooseMatnor);
    
            tv_matnr.setText(lips.getMatnr());
            tv_plan.setText(lips.getMenge() + "");
            tv_out.setText(lips.getLfimg() + "");
            tv_lgort.setText(lips.getLgort());
    
            cb_chooseMatnor.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        checkedPosition = position;
                        LipsListAdapter.this.notifyDataSetChanged();    
                    }
                }
            });
    
            cb_chooseMatnor.setChecked(checkedPosition == position ? true : false);
    
            return convertView;
        }
    
    }
  • 相关阅读:
    Unbutu之web环境部署——常用软件安装
    利用百度uaredirect.js判断手机终端并自动跳转
    原生Ajax附件上传简单实例
    shader glsl 函数图举例
    pixijs释放纹理的方法
    pixijs shader透明度设置方法
    pixijs 用canvas的方法
    threejs 解决模型缩小有黑边的解决方案
    threejs 透明模型遮挡后面模型解决方案
    javascript canvas 清除图片空白多余的方法
  • 原文地址:https://www.cnblogs.com/arnoid/p/3171686.html
Copyright © 2011-2022 走看看