栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

android中的自定义复选框难度

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

android中的自定义复选框难度

class imageCheckBoxAdapter extends ArrayAdapter<String> implements View.onClickListener{    private final Context context;    private final ArrayList<String> values;    private final Map< String, SmbFile> obj;    private ArrayList<Boolean> checks=new ArrayList<Boolean>();    public imageCheckBoxAdapter(Context context,ArrayList<String> values,Map< String, SmbFile>obj)     {        super(context, R.layout.row_checkbox, values);        this.context = context;        this.values = values;        this.obj=obj;        for (int i = 0; i < values.size(); i++) { checks.add(i, false);        }    }    @Override    public View getView(int position, View convertView, ViewGroup parent) {        LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE);        View rowView = inflater.inflate(R.layout.row_checkbox, parent, false);        TextView textView = (TextView) rowView.findViewById(R.id.text1_check);        CheckBox chk = (CheckBox) rowView.findViewById(R.id.checkBox1);        textView.setText(values.get(position));        ImageView imageView = (ImageView) rowView.findViewById(R.id.icon_image_check);        try        { if((obj.get(values.get(position)).isFile())) {     imageView.setImageResource(R.drawable.view_file_icon); } else {     imageView.setImageResource(R.drawable.view_folder_icon); }        }        catch (SmbException e)         { Toast.makeText(context,"Network error",Toast.LENGTH_SHORT).show(); Log.d("id1", "error1"); e.printStackTrace();        }        chk.setTag(Integer.valueOf(position));        // Set a listener for the checkbox        chk.setonClickListener(this);        //Sets the state of CB, since we have the list of checked CB        chk.setChecked(checks.get(position));        return rowView;    }    @Override    public void onClick(View view) {        Integer index = (Integer)view.getTag();        boolean state = checks.get(index.intValue());        checks.set(index.intValue(), !state);    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/497057.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号