Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development > Developer 101

Developer 101 101 Tutorials



Reply
 
LinkBack Thread Tools
Old January 22nd, 2012, 08:14 PM   #1 (permalink)
New Member
 
Join Date: Jan 2012
Posts: 2
 
Device(s):
Thanks: 1
Thanked 0 Times in 0 Posts
Default How to display a text file

can someone point me in the right direction. not sure even what to search for. trying to display a text file in app. anything would help right now.

ronguilmet is offline  
Reply With Quote
Sponsors
Old January 23rd, 2012, 01:45 AM   #2 (permalink)
Premium Member
 
Join Date: Oct 2011
Location: Sydney, Australia
Posts: 193
 
Device(s): Galaxy Nexus GSM
Thanks: 2
Thanked 37 Times in 33 Posts
Default

Where is the text file stored? Is it plain text or do it contain formatting markup? How big is the file?
jiminaus is offline  
Reply With Quote
Old January 23rd, 2012, 05:02 AM   #3 (permalink)
New Member
 
Join Date: Jan 2012
Posts: 2
 
Device(s):
Thanks: 1
Thanked 0 Times in 0 Posts
Default

I don't have the file anywhere yet because I don't know where to start or what methods to use.. I want to click on a listactivity and display the file. maybe I should be puttinig in a DB not sure. file is about 2megs. I have it in pdf also. either would work.
ronguilmet is offline  
Reply With Quote
Old January 23rd, 2012, 04:12 PM   #4 (permalink)
Senior Member
 
Join Date: Jul 2010
Posts: 977
 
Device(s): Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Thanks: 52
Thanked 199 Times in 144 Posts
Default

Code:
public String readFile(BufferedReader br)
{
    StringBuilder sb = new StringBuilder();
    String tmp;

    try
    {
         while((tmp = br.readLine()) != null)
             sb.append(tmp).append("\n");
     }
    catch(IOException e)
    {
          Toast.makeText("Failed to read file").show();
          return null;
    }

    return sb.toString();
}
This returns a string containing the text file. All you need to do is set the textview's text to the returned string and you should be good to go.
jonbonazza is online now  
Reply With Quote
The Following User Says Thank You to jonbonazza For This Useful Post:
ronguilmet (January 24th, 2012)
Reply

Bookmarks


Go Back   Android Forums > Android Development > Application Development > Developer 101 User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 08:17 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo