我想在下面的代码中动态创建复选框。复选框显示正常,但它没有显示通过setText()添加的与之关联的文本。这是我调用方法的地方:
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;
}
请帮帮我。谢谢。