0

In my android project, I get a string from my server and from that string put the value inside a textview.

XML:

<RelativeLayout
    android:id="@+id/scorelayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical">

Java:

RelativeLayout relativeLayout = view.findViewById(R.id.scorelayout);
TextView Score = new TextView(context);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
    RelativeLayout.LayoutParams.WRAP_CONTENT, 
    RelativeLayout.LayoutParams.WRAP_CONTENT
);
relativeLayout.addView(Score, layoutParams);
Lauri
  • 25
  • 7

2 Answers2

2

This can be done by these three steps:

Step1: You can make use a textview in Android and make it invisible(Xml property).

Step2: After making the textview you can assign the dynamic string which you are getting to the textview by the help of java in java class by setText() method.

step3: make its visibility to visible by using java code.

I hope that will help. If you need more help regarding this feel free.

umairnsr87
  • 91
  • 7
1

The simplest solution for you will be to set your TextView in xml and set

android:visibility="gone"

And when you have to show your text just do it like

myTextView.setText(myText);
myTextView.setVisibility(View.VISIBLE);

But if you are looking just an answer how to add view programmatically here is a link https://stackoverflow.com/a/10419021/5422725