Android单选中listview中的一项

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;
    }

}