Managing many views

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Managing many views

Postby Tomas » Sun Sep 20, 2009 1:12 pm

Hi

I have my application that has to show quite a few views. For example, there is the login view, which takes their details. They click to log in and then they go to the profile view, which shows them their information. Then there are the search, search results and various others.

I'm hitting this problem though. I'm trying to go down the OO route and I don't know the best way to manage my views. I created my activity, with this function:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void setView(Page newPage)
  2.  
  3.     {
  4.  
  5.         if(mCurrentPage!=null)
  6.  
  7.                 mCurrentPage.onExit();
  8.  
  9.  
  10.  
  11.         mCurrentPage = newPage;
  12.  
  13.         mCurrentPage.setAsCurrent();
  14.  
  15.         mCurrentPage.onEnter();
  16.  
  17.     }
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


Page is a base class where the other pages are derived from, for example LoginPage extends Page and looks a little bit like this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class LoginPage extends Page
  2.  
  3. {
  4.  
  5.         public LoginPage(my_activity_class parent)
  6.  
  7.         {
  8.  
  9.                 super(parent);
  10.  
  11.                 _layout = R.layout.login;
  12.  
  13.         }
  14.  
  15.        
  16.  
  17.         @Override
  18.  
  19.         public void onEnter()
  20.  
  21.         {
  22.  
  23.                 Button login = (Button)_parent.findViewById(R.id.cmd_login);
  24.  
  25.                 login.setOnClickListener(new OnClickListener()
  26.  
  27.                 {
  28.  
  29.                         @Override
  30.  
  31.                 public void onClick(View v)
  32.  
  33.                 {
  34.  
  35.                                 //Do login stuff
  36.  
  37.                 }
  38.  
  39.             });
  40.  
  41.         }
  42.  
  43. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


But that is posing a problem, because once the login page has successfully logged the user in, the user data is contained in this login page AND it has to tell the parent to switch views.. which is going to cause issues because the parent will then destroy the login page and replace it with the profile page.

So I'm looking for a better way, but I don't know what that way is. Ideally, the Activity should be able to create views/pages and views/pages need a way to indicate that they should be changed, however the page class (or derived - eg LoginPage) shouldn't need to keep an instance of the parent (Activity) class.

So I'd like to know how other people are managing their views and if anyone can give me some guidance to designing this application properly.
Tomas
Freshman
Freshman
 
Posts: 5
Joined: Sun Sep 20, 2009 1:00 pm

Top

Postby wiederke » Mon Sep 21, 2009 12:19 pm

Hi,

you should create a new Activity for each Page you have
- one Login Activity
- one Profile Activity
- one Search Activity

Each Activity should handle its own function.

Using one Activity and playing hide and seek with a lot of views is the wrong application architecture.



bye,

Torsten
wiederke
Experienced Developer
Experienced Developer
 
Posts: 72
Joined: Mon Mar 02, 2009 6:46 pm
Location: Germany

Postby Tomas » Mon Sep 21, 2009 1:07 pm

Thank you for the advice.

I was looking through the demos today and I found the api demos which give a good example of an application with many pages.

Now I'm off to start my app again, the right way this time :lol:
Tomas
Freshman
Freshman
 
Posts: 5
Joined: Sun Sep 20, 2009 1:00 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 11 guests