0

I am writing an android app for a watch (ZGPAX S6). Very small screen, Android SDK 14 target. I intend to run this app without a title bar at the top, or tabs. This will be a full screen app - real estate on a 1.54 inch screen is precious.

I have a single layout in mind, but 10 or more "screens" in the app. Is it possible to manage "logical fragments" instead of actually laying everything out in a layout xml file?

For instance, my screens are all "4 up" - shows 4 data pieces in a grid. I intend to use a swipe gesture to move between a set of logical screens for this app.

  1. 4up (screen A)
  2. 4up (screen B)
  3. 4up (screen C) etc.

Right now I have a single activity, an arraylist that holds "screens" (a title and a type of data) and a single layout file that has the 4up elements coded into it. I use a click handler to move to the next spot in the arraylist and repaint the elements on the screen. The data elements themselves are being read off of a network connection and refreshed to the screen as they come in. This part works great.

I want to use all screen transitions along with my gesture to make it look like a horizontal scrolling list of these screens, but there is only 1 of them... So I would draw screen 1, swipe right to get to screen 2, swipe right to get to screen 3 etc.

The progression of the application looks like this (pseudocode):

onCreate{
   get handles to the elements of the layout   
   setupScreenData() - this sets up the arraylist of "screens"
   run the network listener() - this starts a thread and connects to the activity via a Handler
}

//this happens when I get data from the network
handleMessage{
   //this combines data in the screens array with data sent back from the network
   refreshScreenData()
}

onClick{
   increment the pointer in the screen array
}
ligi
  • 39,001
  • 44
  • 144
  • 244
JuddGledhill
  • 149
  • 1
  • 1
  • 11

1 Answers1

1

It turns out that the logical screens are called "fragments" and you need to use a viewpager to get the behavior I am looking for. Here is an SO post that describes what direction I am using at the moment:

How to implement a ViewPager with different Fragments / Layouts

Community
  • 1
  • 1
JuddGledhill
  • 149
  • 1
  • 1
  • 11
  • Also, make an abstract fragment class having all the features which are "common" among the screens. Then just extend this class and customize for each screen. – S.D. Oct 06 '14 at 14:43
  • One thing that I am running into now is that I have a fragment that I can draw to the screen and a viewpager that swipes between them. Just like the example. Now I do not know how to "reach into" one of the fragments to update a textview inside of it... – JuddGledhill Oct 06 '14 at 14:59
  • @S.D. I took your advice and moved along the app some more. Now I am trying to get a reliable handle to the current, onscreen Fragment. I posted the question and code here if you want to take a look... http://stackoverflow.com/questions/26347217/calling-methods-on-the-current-fragment-in-a-viewpager-from-activity – JuddGledhill Oct 13 '14 at 19:14
  • You can always find a fragment by id, or by tag using `FragmentManager`. This fragment must have been added using fragment manager. – S.D. Oct 14 '14 at 08:28
  • @S.D. That did not seem to work for me at all. The FragmentManager did not have that method available, but maybe I was confused... I am exploring a move to EventBus now as it makes more sense in my brain and I should be able to work with it a little better... – JuddGledhill Oct 14 '14 at 20:52