2012-10-19 51 views
0

我想在下面的代码中动态地创建复选框。复选框显示正常,但没有显示与它通过setText()添加的相关文本。调用方法:添加CheckBox动态难度

ArrayList<String> FilesInFolder = GetFiles(Environment.getExternalStorageDirectory()+File.separator+"Naseeb" 
,getApplicationContext()); 

这是代码:

public static ArrayList<String> GetFiles(String DirectoryPath,Context context) 
    { 
     try 
     { 
      MyFiles = new ArrayList<String>(); 
      File f = new File(DirectoryPath); 

      boolean checker = SdCardManager.CheckIsFileExists(f); 
      if(!checker) 
      { 
       Toast.makeText(context,"there is some problem in creating File f in GetFiles() method in " + 
         "ShowTheFolderrsInSdCard.java" 
         ,Toast.LENGTH_SHORT).show();  
      } 
      Toast.makeText(context,f.getAbsolutePath(),Toast.LENGTH_SHORT).show(); 

      File[] files = f.listFiles(); 
      if (files.length == 0) 
       return null; 
      else { 
       for (int i=0; i<files.length; i++) 
       { 
        CheckBox cbi = new CheckBox(context); 
       // cbi.setText(files[i].getName()); 
        cbi.setText("hello"); 
        ll.addView(cbi); 
       } 
      } 
     } 
     catch(Exception e) 
     { 
      System.out.println(""); 
     } 
     return MyFiles; 
    } 

请帮助me.Thanks提前。

+0

按你几乎贴的代码,你没有得到一个“Hello”文本的所有复选框? – Dharmendra

+0

不,我只得到没有文字的复选框。 – user1726619

+1

尝试更改复选框的颜色。可能是颜色与您当前的主题相匹配。 – Dharmendra

回答