0

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.

3
  • As per youd posted code, Are you not getting the all checkbox with "hello" text? Commented Oct 19, 2012 at 7:29
  • No,i am only getting the checkbox without text. Commented Oct 19, 2012 at 7:31
  • 1
    Try to change the color of the checkbox. May be color is matching with your current theme. Commented Oct 19, 2012 at 7:33

1 Answer 1

1

Set the background color like

cbi.setBackgroundColor(Color.BLACK);

Refer the following link to add the view dynamically .

Adding views programatically

Sign up to request clarification or add additional context in comments.

1 Comment

Set the background color like cbi.setBackgroundColor(Color.BLACK);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.