-1

I want to add a TextView dynamically to the SlidingDrawer. Below is my XML code:

<SlidingDrawer
    android:id="@+id/sdDrawerBottom"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_alignParentBottom="true"
    android:content="@+id/sdBottomContent"
    android:handle="@+id/sdBottomHandle"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/sdBottomHandle"
        android:layout_width="50dp"
        android:layout_height="20dp"
        android:background="@drawable/shape_rounded_corners_blue_top"
        android:scaleType="center"
        android:src="@drawable/icon_arrow_up_white" />

    <LinearLayout
        android:id="@+id/sdBottomContent"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:orientation="vertical"
        android:scrollbars="vertical" >

        <LinearLayout
            android:id="@+id/llBottomNavigation"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="horizontal"
            android:scrollbars="horizontal" >
        </LinearLayout>
    </LinearLayout>
</SlidingDrawer>

And this is my java code:

LinearLayout llBottomNavigation = (LinearLayout) mButtonsView
            .findViewById(R.id.llBottomNavigation);
for (int i = 0; i < navigationList.size(); i++) {
        TextView tvTab = new TextView(this);
        tvTab.setText(Content.getTitle(navigationList.get(i)));
        tvTab.setId(i);
                  tvTab.setTextColor(getResources().getColor(android.R.color.black));
        tvTab.setTextSize(12);
        if (Hardware.getScreenSize(this) > 4) {
            tvTab.setLayoutParams(new    LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT));
        } else {
            tvTab.setLayoutParams(new   LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT));
        }           tvTab.setSingleLine(true);
        tvTab.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

            }
        });
        llBottomNavigation.addView(tvTab);
        llBottomNavigation.invalidate();
    }

It's not adding any TextViews to the SlidingDrawer. Is there any mistake in my code?

Mahm00d
  • 3,881
  • 8
  • 44
  • 83
unflagged.destination
  • 1,576
  • 3
  • 19
  • 38

1 Answers1

0

@unflagged.destination , while addView you shoud pass layoutparams with view... try this...

SlidingDrawer slidingDrawer = (SlidingDrawer) findViewById(R.id.slidingDrawer);
LinearLayout llBottomNavigation = (LinearLayout) slidingDrawer.findViewById(R.id.llBottomNavigation);
for (int i = 0; i < 10; i++) {
    System.out.println("in loop, " + i);
    TextView tvTab = new TextView(this);
    tvTab.setText("item "+i);
    tvTab.setId(i);
    tvTab.setTextColor(getResources().getColor(android.R.color.black));
    tvTab.setTextSize(12);
    /*          if (Hardware.getScreenSize(this) > 4) {
        tvTab.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    } else {
        tvTab.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    }           tvTab.setSingleLine(true);*/

    tvTab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

        }
    });

    LinearLayout.LayoutParams paramsFortvTab = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    llBottomNavigation.addView(tvTab, paramsFortvTab);
    //llBottomNavigation.invalidate();
}

if any query, plz ask...

Rumit Patel
  • 8,830
  • 18
  • 51
  • 70