I am trying to add a very long text (Glgamesh's epic) in a fragment.
My xml version:
<LinearLayout.LayoutParams xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".viewOne">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/epica"
android:text=" **I WILL INSERT HERE THE WHOLE TEXT?**" />
</LinearLayout.LayoutParams>
also what's the java part? do I have to rewrite the content in setText? Can I recall it just by ID?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dynamic_linearlayout);
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.epica);
TextView textView = new TextView(this);
textView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
Hey, thanks!
If you are trying to make and APP like a book with pages you can't do it like this. You have to create a database to store the content of each page. Then you can load page by page to the text view when user hits a button.
The java code you have provided is can be changed as below.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dynamic_linearlayout);
TextView epica = (Textview) findViewById(R.id.epica);
epica.setText("Some text here");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.