1

First let me say that I'm very new to android development (although I have a good understanding of the basics of java), and I am building a magazine reader app for a campus publication I work for.

I want to display each article using a ViewPager widget. I'm going to build a java program which enables the magazine editor to post articles in .txt format onto a server, along with images associated with each, and have the android app periodically download these articles to a local folder.

I'm a little confused about how to construct the views for each ViewPager from the text files. Somehow my logic needs to determine the size of the screen running the app, in order to know how many words can fit on each screen.

Is this right, or am I fundamentally misunderstanding ViewPager somehow? If so, how might I structure the program to configure the views dynamically based on the txt + images given to it?

drew moore
  • 31,565
  • 17
  • 75
  • 112
  • Your approach scares me a little. Look into soa (service orientated architecture) which may result in you implementing a Web service. I realise this is off topic but only trying to help. – Graham Smith Jan 19 '13 at 23:47
  • does it scare you because it would be too resource-intensive on the android devices? I was worried about this. I appreciate your help - what are you suggesting that I implement the web service for, exactly? – drew moore Jan 19 '13 at 23:51
  • I have implemented what you want several times over. I would implement a RESTful API (web service). Your web service can communicate with a database, which is used for your persistent storage. Your content creators can then use the application you created to add/update articles via the API. The Android app can then get a list of say the latest 10 articles (most likely in JSON or XML) http://site.com/service/list and populate a the ViewPager items by deserialising the response into objects. You could use GSON or something similar. – Graham Smith Jan 20 '13 at 02:00

1 Answers1

1

From what I understand, each page will contain as much of the article as possible, and when the user selects the article they will be able to see the entire thing. Something like this, but so it fills up the entire screen?

pulse

If this is the case, you have two options here:

  1. Just ellipsize the textview so that it ends with a "..." at the end. Probably the preferred solution.
  2. Resize the TextView to fit all your text (Auto Scale TextView Text to Fit within Bounds).

EDIT: Here's a different interpretation of your question.

From what I understand, you're trying to have something like an eBook reader with an undefined number of pages; kind of what Flipboard does:

Flipboard

Basically, once all the text fills in the entire area you want to have it continue to the next page.

The easiest way to do this, if you do not need native performance, would be to just use a WebView, split the text across several columns, and have only one column be visible at a time.

However, it is certainly possible to calculate how tall the entire text would be and then split it up accordingly; i.e. Pagination in Android TextView

It seems similar questions have been asked and addressed: Splitting a TextView into multiple TextViews relative to screen height (see the accepted answer).

Community
  • 1
  • 1
Oleg Vaskevich
  • 12,444
  • 6
  • 63
  • 80
  • Not quite. I actually have a listview that the user can use to scroll through the different articles. When they select one of them, I want them to be able to view the entire article in a viewpager. So how do I construct the views to plug into the viewpager, such that each view has enough of the text to fill the screen. Are you saying that elipsizing the textview can somehow automatically help me with this? – drew moore Jan 20 '13 at 00:12
  • Hmm.. perhaps I can use getElipsisCount to figure out how many pages the article requires, and then use a for loop to create and populate each page? Something like for(curr = 0; curr < myTextView.getElipsisCount(); curr++)? I also wonder whether fragments would be useful to me here, but I haven't yet wrapped my head around exactly what they are/do... – drew moore Jan 20 '13 at 00:18