Michael Ellis
Michael Ellis

Reputation: 378

Android TextView not showing all of my text

Im making a mad lib and am getting user input and then removing the input controls and displaying a text result in a TextView. I also use a stringbuilder, and arrayLists of a strings. I tried with both the stringbuilder and arraylists to just put all the text into the textview multiple ways but it only ever displays maybe half.

My control

<TextView
        android:text=""
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/word1_editText"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginLeft="26dp"
        android:layout_marginStart="26dp"
        android:visibility="invisible"
        android:maxLength="1000"
        android:maxLines="20"
        android:scrollbars="vertical"
        android:id="@+id/madlib1_textView" />

and the below button code will alow for input and then after 19 times it will remove the button and display the text

ArrayList<String> prompts = new ArrayList<>();
ArrayList<String> madLibText = new ArrayList<>();
ArrayList<String> finalMadLib = new ArrayList<>();
RelativeLayout layout;
private int promptNum;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_madlib1);
    layout = (RelativeLayout) findViewById(R.id.activity_madlib1);
    promptNum = 0;
    /* OTHER INIT STUFF */
}

public void submitWords(View v) {
    finalMadLib.add(madLibText.get(promptNum));
    EditText word1 = (EditText) findViewById(R.id.word1_editText);
    finalMadLib.add(word1.getText().toString());
    word1.setText("");
    word1.setHint(prompts.get(promptNum));
    promptNum++;
    if (promptNum == 18) {
        StringBuilder temp = new StringBuilder("");

        TextView textView = (TextView)findViewById(R.id.madlib1_textView);
        for(int i=0;i<19;i++){
           // temp.append(finalMadLib.get(i).toString());
            textView.append(finalMadLib.get(i).toString());
        }
        textView.setVisibility(VISIBLE);
       // textView.setText(temp.toString());
        textView.setId(promptNum);
        textView.setTextSize(15);
        layout.removeView(findViewById(R.id.word1_editText));
        layout.removeView(findViewById(R.id.submitwords_button));
    }
}

Why is it only displaying 4 total lines and about 10/19 or 20/48 pieces of the final text/string result in the TextView? I am using android studio, windows 10, and the built in emulator. I feel that my issue is different than the other similar questions, I have tried the accepted fixes and other stuff without success.

Upvotes: 1

Views: 9562

Answers (2)

cpienovi
cpienovi

Reputation: 410

Remove

android:maxLength="1000"

So it will look like this:

<TextView
    android:text=""
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/word1_editText"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginLeft="26dp"
    android:layout_marginStart="26dp"
    android:visibility="invisible"
    android:maxLines="20"
    android:scrollbars="vertical"
    android:id="@+id/madlib1_textView" />

And add this to your activity's onCreate to make it scrollable:

TextView txtMadlib = (TextView) findViewById(R.id.madlib1_textView);
txtMadlib.setMovementMethod(new ScrollingMovementMethod());

Upvotes: 4

Andrey  Kopeyko
Andrey Kopeyko

Reputation: 1566

You can wrap your TextView with ScrollView to be able to see full text:

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/device_info"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:text="device info" />

</ScrollView>

Upvotes: 0

Related Questions