mercredi 27 janvier 2016

Unable to show elements (checkbox or text view) inside layout Android

I want to programmatically add checkboxes inside a LinearLayout who are inside a fragment.

Right now, I'm able to show my first level (textView). I see the space that my checkboxes are supposed to take but nothing appears. Here's my code.

FRAGMENT BACKEND

Context context = activity.getApplicationContext();
List<SousSection> listSousSection = SousSectionService.getSousSectionById(activity, section);
Iterator<SousSection> iterSousSection = listSousSection.iterator();
while (iterSousSection.hasNext()) {
        SousSection sousSection = iterSousSection.next();
        LinearLayout layout = new LinearLayout(context);
        TextView textview = new TextView(context);
        textview.setTag(sousSection.getId());
        textview.setText(sousSection.getTitres().iterator().next()
                .getTitre());
        textview.setGravity(Gravity.CENTER);
        textview.setTextColor(context.getResources()
                .getColor(R.color.black));
        textview.setTextSize(20);
        textview.setTypeface(null, Typeface.BOLD);
        textview.setLayoutParams(new LayoutParams(
                LayoutParams.MATCH_PARENT,   LayoutParams.WRAP_CONTENT));
        layout.addView(textview);

        List<TextSousSection> listTextSousSection = TextSousSectionService.getTextSousSectionBySousSectionId(activity, sousSection);
        Iterator<TextSousSection> iterTextSousSection = listTextSousSection
                .iterator();


        while (iterTextSousSection.hasNext()){
            TextSousSection textSousSection = iterTextSousSection.next();

            CheckBoxWithParam checkbox = new CheckBoxWithParam(
                    context);
            checkbox.setTag(textSousSection.getId());
            checkbox.setChecked(!CheckTextService.isCheckedText(activity, textSousSection));
            //checkbox.setEms(10);
            checkbox.setTextColor(context.getResources().getColor(
                    R.color.black));
            checkbox.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

            if (!textSousSection.getHasParam()) {
                checkbox.setText(textSousSection.getText());
            } else {
                /*do stuff*/
            }

            layout.addView(checkbox);

        }

        parentView.addView(layout);
    }

FRAGMENT FRONTEND

<FrameLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragment.SectionMasterFragment">

<!-- TODO: Update blank fragment layout -->
<LinearLayout
    android:id="@+id/parentView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:orientation="vertical" >
</LinearLayout>

</FrameLayout>

I also tried with a basic textview, but it stills does not works. Could you help me? thanks




Aucun commentaire:

Enregistrer un commentaire