Android: Textview does not display setpoint programmatically

I want to set the textview value programmatically, everything seems fine to me, but I don’t know why the set value does not appear

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 text view is not displayed when the application starts.

UPDATE //////// Full 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>
+4
source share
4 answers

Maybe there is something ahead, try:

textView.bringToFront();
0
source

Add the code below to your xml and run the application. Let me know what will happen.

    android:text="New Text" 
+3
source

android:textColor.

android:textColor="#000000"

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

, Log.d.

Log.d , XML.

+2
source

Check that there is idno conflict. Please make sure that you do not have the same identifier TextViewin the two fragments for the tab in viewpagerIf you use these ...

0
source

Source: https://habr.com/ru/post/1620280/


All Articles