0

So, I'm making my first Android application, which basically contains ~250 .txt files in the asset folder. I list them all in a ListActivity, so you can choose the one you want to read and then open it in a TextView. The app is working just fine in the emulator, no problemo. However, when I install the .apk on my phone, the longest .txt files get cut off, mid-sentence. This does not happen on the emulator. I'm at a loss, I have no clue what could be causing this, but if anyone has any ideas, I would be happy to explore them!

Here's the code, I'm still very much learning, and I realize this probably isn't the optimal way to do what I want to do, but anyway, here goes:

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);
    String path = fikBog[position];

    try {

        bog = getAssets().open("skyrimbooks/" + path);
        int size = bog.available();
        byte[] buffer = new byte[size];
        bog.read(buffer);
        bog.close();
        String bookInput = new String(buffer);
        Bundle taske = new Bundle();
        taske.putString("bog", bookInput);
        Intent g = new Intent(GotSkyrimBooks.this, BookReader.class);
        g.putExtras(taske);
        startActivity(g);

    } catch (IOException e) {
        // Should never happen!
        throw new RuntimeException(e);
    }


}

So, in the ListActivity, the user can browse all the different .txt files, and when he/she picks one, it gets opened in the BookReader class. And in the BookReader class, the textview gets populated like so:

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.bookreader);

    reader = (TextView) findViewById(R.id.reader);


Bundle fikTaske = getIntent().getExtras();
fikBog = fikTaske.getString("bog");
reader.setText(fikBog);
}

Here is my .xml. Simple as can be:

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <LinearLayout 
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/reader"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textColor="#000000" />

  </LinearLayout>
</ScrollView>

  • What android version do you run on your phone and what in your emulator? ICS seems to have many issues (or non backward compatible issues) with other android versions. Also you can post some code on how you populate you textview – weakwire Apr 02 '12 at 19:26
  • Please post your layout so we can have an idea of what you're working with in terms of UI. – Jean-Philippe Roy Apr 02 '12 at 19:38
  • @weakwire, both my phone and emulator uses 2.2 –  Apr 02 '12 at 19:46

2 Answers2

1

Some handsets out there seem to set a low maximum default length for TextViews. I would suggest setting the maxLength property in the XML for the TextView to something larger than the files you'd like to view.

If you want to do it programmatically, this answer should help you with that: How to programmatically set maxLength in Android TextView?

Community
  • 1
  • 1
Tom Meyer
  • 141
  • 3
  • I can't believe it was that simple. It actually worked! Cheers, dude! –  Apr 02 '12 at 19:52
  • Are you sure that this will work at all screen sizes / resolutions with any textSize? – weakwire Apr 02 '12 at 20:10
  • This just sets the total amount of text that can be displayed by scrolling within the textview, so it won't be affected by screen sizes and resolutions. – Tom Meyer Apr 03 '12 at 20:30
0

If you want only the text to appear you can remove ScrollView and set a scrolling method to your text. This should work. Check this answer here

Community
  • 1
  • 1
weakwire
  • 9,284
  • 8
  • 53
  • 78