Skip to content

Instantly share code, notes, and snippets.

@JuniiiSays
Last active August 17, 2022 13:02
Show Gist options
  • Save JuniiiSays/9537323768ccd000a8eae930e4bffc32 to your computer and use it in GitHub Desktop.
Save JuniiiSays/9537323768ccd000a8eae930e4bffc32 to your computer and use it in GitHub Desktop.
ArrayList<String> words = new ArrayList<String>();
words.add("One");
//Find the rootView of Numbers activity
LinearLayout rootView = findViewById(R.id.rootView);
//Create a TextView programmatically
TextView wordView = new TextView(this);
//Show first element of the ArrayList ib that TextView
wordView.setText(words.get(0));
//Attach TextView with the rootView
rootView.addView(wordView);
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/rootView"
android:orientation="vertical"
android:padding="16dp"
tools:context=".NumbersActivity">
</LinearLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment