#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Location
    Sacramento Ca. USA
    Posts
    8
    Rep Power
    0

    Trouble with TextView Class


    I can not seem to dynamical put variables on my app. text screen. Within my activity_main.xml file I have created an id like this -
    Code:
    <TextView
             android:id="@+id/dataView1"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_above="@+id/textView2"
             android:layout_marginLeft="36dp"
             android:layout_toRightOf="@+id/textView5"
             android:text="@string/planet_name_label" />
    I am trying to display "dataView1" within my MainActivity.java file like this -
    Code:
    TextView planetNameValue (TextView)findViewById(R.id.dataView1);  
            planetNameValue.setText(earth.planetName);
    Everything complies but my dataView1 does not show up on app screen.
    Thanks in advance.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Location
    Dallas, TX
    Posts
    50
    Rep Power
    1
    Hmm, based on what you have shown, it should show fine. A few things to check:

    - Are the references of "toRightOf" textView5 and "above" textView2 correct? It could be pushing it off the screen if textView2 or textView5 has positioning that causes it to do so. May be worth removing or modifying those lines from your XML temporarily to see if it shows period. I use IntelliJ to do my Android development, and it has a great "preview" option for XML layout files.

    - Is your string resource "@string/planet_name_label" correctly populated with a string? If so, try removing the line from the Java that sets the text to "earth.planetName". It may be setting the TextView's string to "" and you may not be realizing it.

    If neither of the above works, can you post your entire XML layout file? Also, can you put a log statement right before the setText() call, which prints out the value of "earth.planetName"?

IMN logo majestic logo threadwatch logo seochat tools logo