• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps can't able to add textview to linearlayout

Vinoth Vino

Lurker
Mar 24, 2016
4
1
Hi,I'm creating viewpager app. I don't know why my textview is not added to linearlayout. I've the same source code which is downloaded from internet and I created same as the source code but my app unfortunately force stopped automatically. See my comments then you could understand what I'm trying to say...



Code:
  //adding bottom dots

        addBottomDots(0);

      

        changeStatusBarColor();



      private void addBottomDots(int currentPage){



        dots = new TextView[layouts.length];



        int[] colorsActive = getResources().getIntArray(R.array.array_dot_active);

        int[] colorsInActive = getResources().getIntArray(R.array.array_dot_inactive);      //upto here it works fine





        dotsLayout.removeAllViews();

        Log.d("removeallviews executed","success");



        //below code set circle in page with dark colors

        for (int i=0; i<dots.length;i++){



            dots = new TextView(this);

            dots.setText(Html.fromHtml("&#8226;"));

            dots.setTextSize(35);

            dots.setTextColor(colorsInActive[currentPage]);

            dotsLayout.addView(dots);

      

        }



        if (dots.length >0){



            dots[currentPage].setTextColor(colorsActive[currentPage]);

        }

    }

Above code execute successfully upto **colorsInActive** if I comment the **dotsLayout.removeAllViews()** then it'll execute upto **dots.setTextColor(colorsInActive[currentPage]);** and it stopped working when **dotsLayout.addView(dots);** method executed

Code:
      //adding bottom dots

        addBottomDots(0);

      

        changeStatusBarColor();



      private void addBottomDots(int currentPage){



        dots = new TextView[layouts.length];



        int[] colorsActive = getResources().getIntArray(R.array.array_dot_active);

        int[] colorsInActive = getResources().getIntArray(R.array.array_dot_inactive);  





      // dotsLayout.removeAllViews();

      //  Log.d("removeallviews executed","success");



        //below code set circle in page with dark colors

        for (int i=0; i<dots.length;i++){



            dots = new TextView(this);

            dots.setText(Html.fromHtml("&#8226;"));

            dots.setTextSize(35);

            dots.setTextColor(colorsInActive[currentPage]);       //upto here it works fine

            dotsLayout.addView(dots);

      

        }



        if (dots.length >0){



            dots[currentPage].setTextColor(colorsActive[currentPage]);

        }

    }



XML Layout

Code:
    <?xml version="1.0" encoding="utf-8"?>

      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

      xmlns:tools="http://schemas.android.com/tools"

      android:layout_width="match_parent"

      android:layout_height="match_parent"

      tools:showIn="@layout/activity_main">



    <android.support.v4.view.ViewPager

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:id="@+id/viewpagerid"/>



    <LinearLayout

        android:id="@+id/dotslayout"

        android:layout_width="match_parent"

        android:layout_height="@dimen/dots_height"

        android:layout_alignParentBottom="true"

        android:layout_marginBottom="@dimen/dots_margin_botton"

        android:gravity="center"

        android:eek:rientation="horizontal">



    </LinearLayout>



    <view

        android:layout_width="match_parent"

        android:layout_height="1dp"

        android:alpha=".5"

        android:layout_above="@id/dotslayout"

        android:background="@android:color/white"/>



    <Button

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignParentRight="true"

        android:layout_alignParentBottom="true"

        android:id="@+id/buttonNextid"

        android:background="[USER=84939]@Null[/USER]"

        android:text="[USER=696546]@String[/USER]/next"

        android:textColor="@android:color/white" />



    <Button

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignParentLeft="true"

        android:layout_alignParentBottom="true"

        android:id="@+id/buttonSkipid"

        android:background="[USER=84939]@Null[/USER]"

        android:text="[USER=696546]@String[/USER]/skip"

        android:textColor="@android:color/white" />



</RelativeLayout>


Please help me.Thanks in advance :)
 
Last edited:
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones