1. Download our Official Android App: Forums for Android!

Apps can't able to add textview to linearlayout

Discussion in 'Android Development' started by Vinoth Vino, Jun 28, 2016.

  1. Vinoth Vino

    Vinoth Vino Lurker
    Thread Starter
    Rank:
    None
    Points:
    6
    Posts:
    4
    Joined:
    Mar 24, 2016

    Mar 24, 2016
    4
    1
    6
    Male
    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 (Text):
    1.   //adding bottom dots
    2.  
    3.         addBottomDots(0);
    4.  
    5.      
    6.  
    7.         changeStatusBarColor();
    8.  
    9.  
    10.  
    11.       private void addBottomDots(int currentPage){
    12.  
    13.  
    14.  
    15.         dots = new TextView[layouts.length];
    16.  
    17.  
    18.  
    19.         int[] colorsActive = getResources().getIntArray(R.array.array_dot_active);
    20.  
    21.         int[] colorsInActive = getResources().getIntArray(R.array.array_dot_inactive);      //upto here it works fine
    22.  
    23.  
    24.  
    25.  
    26.  
    27.         dotsLayout.removeAllViews();
    28.  
    29.         Log.d("removeallviews executed","success");
    30.  
    31.  
    32.  
    33.         //below code set circle in page with dark colors
    34.  
    35.         for (int i=0; i<dots.length;i++){
    36.  
    37.  
    38.  
    39.             dots = new TextView(this);
    40.  
    41.             dots.setText(Html.fromHtml("&#8226;"));
    42.  
    43.             dots.setTextSize(35);
    44.  
    45.             dots.setTextColor(colorsInActive[currentPage]);
    46.  
    47.             dotsLayout.addView(dots);
    48.  
    49.      
    50.  
    51.         }
    52.  
    53.  
    54.  
    55.         if (dots.length >0){
    56.  
    57.  
    58.  
    59.             dots[currentPage].setTextColor(colorsActive[currentPage]);
    60.  
    61.         }
    62.  
    63.     }
    64.  
    65.  

    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 (Text):
    1.  
    2.  
    3.       //adding bottom dots
    4.  
    5.         addBottomDots(0);
    6.  
    7.      
    8.  
    9.         changeStatusBarColor();
    10.  
    11.  
    12.  
    13.       private void addBottomDots(int currentPage){
    14.  
    15.  
    16.  
    17.         dots = new TextView[layouts.length];
    18.  
    19.  
    20.  
    21.         int[] colorsActive = getResources().getIntArray(R.array.array_dot_active);
    22.  
    23.         int[] colorsInActive = getResources().getIntArray(R.array.array_dot_inactive);  
    24.  
    25.  
    26.  
    27.  
    28.  
    29.       // dotsLayout.removeAllViews();
    30.  
    31.       //  Log.d("removeallviews executed","success");
    32.  
    33.  
    34.  
    35.         //below code set circle in page with dark colors
    36.  
    37.         for (int i=0; i<dots.length;i++){
    38.  
    39.  
    40.  
    41.             dots = new TextView(this);
    42.  
    43.             dots.setText(Html.fromHtml("&#8226;"));
    44.  
    45.             dots.setTextSize(35);
    46.  
    47.             dots.setTextColor(colorsInActive[currentPage]);       //upto here it works fine
    48.  
    49.             dotsLayout.addView(dots);
    50.  
    51.      
    52.  
    53.         }
    54.  
    55.  
    56.  
    57.         if (dots.length >0){
    58.  
    59.  
    60.  
    61.             dots[currentPage].setTextColor(colorsActive[currentPage]);
    62.  
    63.         }
    64.  
    65.     }
    66.  
    67.  



    XML Layout

    Code (Text):
    1.  
    2.  
    3.     <?xml version="1.0" encoding="utf-8"?>
    4.  
    5.       <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    6.  
    7.       xmlns:tools="http://schemas.android.com/tools"
    8.  
    9.       android:layout_width="match_parent"
    10.  
    11.       android:layout_height="match_parent"
    12.  
    13.       tools:showIn="@layout/activity_main">
    14.  
    15.  
    16.  
    17.     <android.support.v4.view.ViewPager
    18.  
    19.         android:layout_width="match_parent"
    20.  
    21.         android:layout_height="match_parent"
    22.  
    23.         android:id="@+id/viewpagerid"/>
    24.  
    25.  
    26.  
    27.     <LinearLayout
    28.  
    29.         android:id="@+id/dotslayout"
    30.  
    31.         android:layout_width="match_parent"
    32.  
    33.         android:layout_height="@dimen/dots_height"
    34.  
    35.         android:layout_alignParentBottom="true"
    36.  
    37.         android:layout_marginBottom="@dimen/dots_margin_botton"
    38.  
    39.         android:gravity="center"
    40.  
    41.         android:eek:rientation="horizontal">
    42.  
    43.  
    44.  
    45.     </LinearLayout>
    46.  
    47.  
    48.  
    49.     <view
    50.  
    51.         android:layout_width="match_parent"
    52.  
    53.         android:layout_height="1dp"
    54.  
    55.         android:alpha=".5"
    56.  
    57.         android:layout_above="@id/dotslayout"
    58.  
    59.         android:background="@android:color/white"/>
    60.  
    61.  
    62.  
    63.     <Button
    64.  
    65.         android:layout_width="wrap_content"
    66.  
    67.         android:layout_height="wrap_content"
    68.  
    69.         android:layout_alignParentRight="true"
    70.  
    71.         android:layout_alignParentBottom="true"
    72.  
    73.         android:id="@+id/buttonNextid"
    74.  
    75.         android:background="[USER=84939]@Null[/USER]"
    76.  
    77.         android:text="[USER=696546]@String[/USER]/next"
    78.  
    79.         android:textColor="@android:color/white" />
    80.  
    81.  
    82.  
    83.     <Button
    84.  
    85.         android:layout_width="wrap_content"
    86.  
    87.         android:layout_height="wrap_content"
    88.  
    89.         android:layout_alignParentLeft="true"
    90.  
    91.         android:layout_alignParentBottom="true"
    92.  
    93.         android:id="@+id/buttonSkipid"
    94.  
    95.         android:background="[USER=84939]@Null[/USER]"
    96.  
    97.         android:text="[USER=696546]@String[/USER]/skip"
    98.  
    99.         android:textColor="@android:color/white" />
    100.  
    101.  
    102.  
    103. </RelativeLayout>
    104.  


    Please help me.Thanks in advance :)
     

    Advertisement

    #1 Vinoth Vino, Jun 28, 2016
    Last edited: Jun 28, 2016
  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,841
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,841
    11,440
    1,988
    Male
    Software developer
    South West of England
  3. Vinoth Vino

    Vinoth Vino Lurker
    Thread Starter
    Rank:
    None
    Points:
    6
    Posts:
    4
    Joined:
    Mar 24, 2016

    Mar 24, 2016
    4
    1
    6
    Male
    Okay Thanks.Now see my question,I just updated
     
  4. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,841
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,841
    11,440
    1,988
    Male
    Software developer
    South West of England
    Still not formatted correctly. Take out all the extra line spaces, and indent it properly.

    Also you need to include a stack trace from the Logcat output if your application crashed unexpectedly.
     
  5. panryz

    panryz Lurker
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Jun 24, 2016

    Jun 24, 2016
    3
    0
    5
    Please paste your stack from logcat.
     

Share This Page

Loading...