0

Gday guys, Just trying to make a simple 'Welcome (Insert Username Here)' message on a RelativeLayout activity after successful login. I searched high and low on stack overflow and wasn't able to find anything relative or recent in regards to this hence the post.

I have: Picture without old mate Dave :

enter image description here

But want this: Picture with Dave, Yay.

enter image description here

Being a relative layout I presume I would create an empty TextView in the layout.xml and then do the work in the activity.java using the android:id?

I apologies for my lack of knowledge, I understand it must be painful for some of you.

Cheers

Shivam Kumar
  • 1,892
  • 2
  • 21
  • 33
  • 1
    you searched high and low and haven´t found an example of a very basic programming stuff? Nothing like this:http://stackoverflow.com/questions/19452269/android-set-text-to-textview – Opiatefuchs Dec 11 '16 at 11:52
  • Sure some are similar, however, that one in particular is 3 years old. Who am I to know text+string into one textview hasn't been revised and updated since then? Also, doesn't help when the title wasn't specific to what I was searching for. I can put text in a textview simply by "android:text="Well shit hey!" " but it's not what I am looking for.... – Living Instinkt Dec 11 '16 at 12:15

5 Answers5

1

Yes create a TextView in your xml file and give it an id like android:id="@+id/myUsername"

Now in your Java class create a reference to that textview like

TextView textView = (TextView) findViewById(R.id.myUsername);

textView.setText(usernameString);
Unique LoL Apps
  • 88
  • 1
  • 11
  • Thanks mate, but for the next bit of adding text + Username string from a DB how would I do this? Text being 'Welcome' Username being 'Username' Together they stand as "Welcome Username". If I were to set the TextView in the layout.xml to simply "Welcome ", could I amend the TV by using amendText in my mainactivity.java? – Living Instinkt Dec 11 '16 at 12:03
0

You have one TextView

But you wants same design which you have shared screenshot. You should use extra textview and text user name.

TextView textView = (TextView) findViewById(R.id.username_value);

textView.setText(username);
Mavya Soni
  • 932
  • 7
  • 15
0

you can check this example for db usage in Android, it's kinda old but could be still relevant for you. There are tons of other similar ones. This looks pretty basic and straightforward. Hope it helps.

https://examples.javacodegeeks.com/android/core/database/android-database-example/

peresisUser
  • 1,680
  • 18
  • 23
0

I post this just in case you need to do it with an intent, anyway it's always the same principle.

Intent iMaine=getIntent();
    titolo=(TextView) findViewById(R.id.titolo_formule);
    titolo.setText(iMaine.getStringExtra("titolo"));
0

Use XML file to change the Material TextView color

 <com.google.android.material.textview.MaterialTextView
    android:id="@+id/tx_demo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

Use Java code

    txDemo = findViewById(R.id.tx_demo);
    txDemo.setText("Welcome Text");
    txDemo.setText(getResources().getString(R.string.app_name));
    txDemo.setText(getIntent().getStringExtra("Key"));

OR Use Kotlin code

    txDemo = findViewById(R.id.tx_demo)
    txDemo!!.text = "Welcome Text"
    txDemo!!.text = resources.getString(R.string.app_name)
    txDemo!!.text = intent.getStringExtra("Key")