Reputation: 941
I want to create the checkbox dynamically in the following code.The checkbox is getting displayed fine,but it is not showing the text associated with it which added through setText().This is where i am calling the method:
ArrayList<String> FilesInFolder = GetFiles(Environment.getExternalStorageDirectory()+File.separator+"Naseeb"
,getApplicationContext());
This is the code:
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;
}
Please help me.Thanks in advance.
Upvotes: 0
Views: 128
Reputation: 3117
Set the background color like
cbi.setBackgroundColor(Color.BLACK);
Refer the following link to add the view dynamically .
Upvotes: 1