如何在gridview中添加复选框?

时间:2013-04-29 21:28:35

标签: android

这是我下面的代码,它使用了简单的适配器,请告诉我如何在我的代码中添加复选框?所以用户使用复选框选择多张图片并执行删除等操作?请帮助我pleaseee帮助我,我想在我的gridview im中添加复选框使用简单的适配器,这是默认的Android适配器我该怎么办?我该怎么修改???我该怎么做????

    File root1;
 String filePath;
     File currentParent;
     File[] currentFiles;
     GridView gridView;

        File photos = new File(getFilesDir(), "Photos");
    photos.mkdirs();

    root1 = new File("/data/data/com.myexample.folder/files/");

    currentParent = root1;
    currentFiles = root1.listFiles();

    currentFilePath = new String[currentFiles.length];
    int count = 0;

    for (File f : currentFiles) {
        currentFilePath[count] = f.getAbsolutePath();
        count++;
    }

    gridView = (GridView) findViewById(R.id.grid);
    gridView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,   
                      int position, long id) {



            if (currentFiles[position].isDirectory()) {

                root = new File("/data 
  /data/com.myexample.folder/files/"+ FileName(currentFilePath[position]) + "/");

textView.setText(FileName(currentFilePath[position]));
                Log.e("Root first", root + " ");

                currentFiles = root.listFiles();

                inflateListView(currentFiles);
            } else if (currentFiles[position].isFile()) {

                openFile(currentFiles[position]);


            }}});


                private void inflateListView(File[] files) {


    List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>();

    for (int i = 0; i < files.length; i++) {
        Map<String, Object> listItem = new HashMap<String, Object>();

        if (files[i].isDirectory()) {


            listItem.put("icon", R.drawable.folder);
            listItem.put("fileName", files[i].getName()+"(" 
                               +files[i].list().length+")");
        } else {



        //  
            listItem.put("icon", files[i]);

        }


        listItems.add(listItem);
    }

    simpleAdapter = new SimpleAdapter(this, listItems, R.layout.line,new 
                      String[] { "icon", "fileName" }, new int[] { R.id.icon,
                    R.id.file_name });

    gridView.invalidateViews();
    gridView.setAdapter(simpleAdapter);

    simpleAdapter.notifyDataSetChanged();



  }

1 个答案:

答案 0 :(得分:0)

The android documentation有一个非常好的小部件列表,它们的作用以及它们的名称。学习如何使用文档很好!

回答你的问题,this is the page for checkboxes