0

I am trying to make a m-learning app and in this app I have a activity in witch the user reads text . After I made the activity scrollable i stumbled apon a supid basic problem ... how do i add the text to the activity ? I don't know if i need to use TextView and if yes then how do I modify it to show all the text I need. I will put below all the code:

-activity java :

public class displayCursI extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_display_curs_i);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }

}

- activity xml :

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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.andrei.licenta_3.displayCursI"
tools:showIn="@layout/activity_display_curs_i">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true">
    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="132dp"
        android:layout_marginTop="105dp"
        android:text="@string/text"
        android:textAlignment="center" />
</ScrollView>

- string xml

<string name="app_name">Licenta_3</string>
<string name="action_settings">Settings</string>
<string name="button_cursuri">Cursuri</string>
<string name="button_chestionar">Chestionar</string>
<string name="title_activity_display_cursuri">displayCursuri</string>
<string name="button_I">I</string>
<string name="button_II">II</string>
<string name="button_III">III</string>
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

1 Answers1

0

In my opinion, the most effective way would be to set up one or more strings within the strings.xml and using the \n escape sequence to force a linebreak whenever needed.

You'll find this file in your project under res/values/strings.xml

Hope it helps.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • I get what you are saying but i need to add la full pages of text books text and i was wondering if i can do it in "text box " kind of way where i can copy the text frome mome were and paste it in – Andrei Dumitru Jun 28 '17 at 22:59
  • You can try also this, i would say you cant go wrong with a textView with `wrap_content` for `height` and `width`, nested inside a scroll view. – Alex Mamo Jun 28 '17 at 23:07
  • coud you post me an exaple ? because i am new to this and don't whant to screw up – Andrei Dumitru Jun 28 '17 at 23:11
  • A good example you can read in this [post](https://stackoverflow.com/questions/11204336/how-to-add-external-css-file-on-html-page-in-android). You'll achieve this with the help of `WebView`. – Alex Mamo Jun 28 '17 at 23:18
  • Yea so the webView is a good option bun is not good for what i am trying :( – Andrei Dumitru Jun 29 '17 at 12:16
  • Try to take a look at this [post](https://stackoverflow.com/questions/14335988/best-practice-to-show-big-text-data-in-an-android-view) too. – Alex Mamo Jun 29 '17 at 12:22
  • So Alex I foud a way to do what I what by using "large_text" and it is similat to what you first propose. thank you – Andrei Dumitru Jun 29 '17 at 14:37
  • Good to hear that. So, if you think that my answer helped you in any way, please consider accepting it and/or giving a +1. Thanks! – Alex Mamo Jun 29 '17 at 14:40