如何在simpleadapter中添加复选框

时间:2013-04-23 05:26:22

标签: android

如何在gridview中添加复选框?下面是我的代码,但我想添加复选框并根据复选框选择执行操作我该怎么办?如何在简单适配器中添加复选框?因为SimpleAdapter是默认适配器我如何更改它们?我该怎么做才能帮助我

 SimpleAdapter simpleAdapter;
 GridView gridView;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

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

File root1 = new File("/data/data/com.newsoftwares.folderlock/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.folderlock
     /files/"+FileName(currentFilePath[position])+"/");

        Log.e("Root first",root+ " ");

        currentFiles = root.listFiles();

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

    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);
    }
    else
    {
        listItem.put("icon", R.drawable.file);
    }

    listItem.put("fileName", files[i].getName());
    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.setAdapter(simpleAdapter);

0 个答案:

没有答案