Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Textview not showing the value set programatically

Tags:

java

android

I want to set the value of textview programatically, everything seems okay by me but dont know why the set value is not appearing

This is the code:

//set the value of a text view
            final TextView textView = (TextView) findViewById(R.id.validityValue);
            textView.setText("30 days");

This is what I have in my xml file

<TextView 
        android:id="@+id/validityValue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:textSize="12sp"
        android:textColor="#000" />

With the above code, the textview is not showing when the application launched.

UPDATE//////// Complete xml code

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

  <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"         
     android:background="@drawable/mobilegrd"
     android:padding="10dp"
     android:layout_height="wrap_content">
  <LinearLayout
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical">
   <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:textSize="25sp"
        android:gravity="center_horizontal"
        android:textColor="#000"
        android:text="Weekly Updates" />
  <Spinner
      android:id="@+id/spinTunes"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="6sp"
      android:textColor="#000"
      android:prompt="@string/tune_prompt" />

  <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:textColor="#000"
        android:text="Singer:" />

<EditText
    android:id="@+id/singer"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:textColor="#000"/>

    <!-- android:inputType="phone"  -->
<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:textColor="#000"
        android:text="Language:" />

<EditText
    android:id="@+id/language"
    android:inputType="phone"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:textColor="#000"/>

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:textColor="#000"
        android:text="Price:" />

<EditText
    android:id="@+id/price"
    android:inputType="phone"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:textColor="#000"/>

<TextView 
        android:id="@+id/validityValue"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_vertical"
        android:textSize="12sp"
        android:textColor="#000000" />

<EditText
    android:id="@+id/validity"
    android:inputType="phone"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:textColor="#000"/>

<Button 
    android:id="@+id/proceed"
    android:text="Proceed"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:textColor="#000"/>

</LinearLayout>
</ScrollView>
like image 399
Blaze Avatar asked Dec 16 '15 08:12

Blaze


3 Answers

Review properly that id is not conflicted..Please be sure that you don't have same id of TextView in two fragments for tab in viewpager If you are using those...

like image 147
Shree Krishna Avatar answered Sep 27 '22 18:09

Shree Krishna


At first Change Your android:textColor .Use This

android:textColor="#000000"

Then

  final TextView textView = (TextView) findViewById(R.id.validityValue);
    textView.setText("30 days");
    String str1 = textView.getText().toString();
    Log.d("++++++",str1);

Then check What Log.d returns .

If Log.d returns properly then post your Total XML .

like image 37
IntelliJ Amiya Avatar answered Sep 27 '22 18:09

IntelliJ Amiya


Add the below code in your xml and run your application. Let me know what happens.

    android:text="New Text" 
like image 37
SachinS Avatar answered Sep 27 '22 20:09

SachinS