• 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;
        }
    
    }
  • 相关阅读:
    C#编程(七十三)----------浅析C#中内存管理
    C#高级编程小结
    C#编程(七十二)----------DynamicObject和ExpandoObject
    C#编程(七十一)----------DLR ScriptRuntime
    C#编程(七十)----------dynamic类型
    C#编程(六十九)----------DLR简介
    C#编程(六十八)----------LINQ小结
    C#编程(六十七)----------LINQ提供程序
    C#编程(六十六)----------表达式树总结
    python 显示上午下午
  • 原文地址:https://www.cnblogs.com/arnoid/p/3171686.html
Copyright © 2020-2023  润新知