Android Question Whats the best way to organize code for many activity pages?

Steve Miller

Active Member
Licensed User
Longtime User
I have an app that has a tabhost on it with 15 tabs. Each tab is loaded with an activity page (I think that's what they are called. The .bal files.) When I generate the variables from the controls, they gets put into the Globals sub of the Main Activity class. I do some loading of various spinners from the database and keep the key/value pair in their individual maps.

To try to organize this so the Main class isn't so massive and unorganized, I created a class module for each tab and moved the SQL loading of the maps there. I tried to put the created variables generated by controls into these classes, but when I try to run the program, I get a java.lang.NullPointerException when I call the initialize of the class.

So, my question is...what is the best way to do this in order to keep it clean, organized and easy to maintain?
 

Steve Miller

Active Member
Licensed User
Longtime User
I've created a project with a single layout on a single tab. There are two textboxes and two spinners. The spinners are loaded from a database.
One textbox and spinner are declared in a class module, the other textbox and spinner are declared in the main activity module. Both spinners are loaded via the class module. One directly in the class module and the other from a call to the class module.

Here is what I am seeing.
1) The spinner loaded from the call to the class module shows data. The spinner declared in the class module and loaded in the class module does not show data.
2) After entering data in the textboxes and selecting from the spinner, clicking the Check Values button logs the values. The controls from the main activity module have data, while the other two do not.

Am I not doing this correctly? I'd really like to separate everything from the layouts into their own class modules, so as to not clutter up the main activity module. Also, this allows for specific logic for each form to be localized for that form.
 

Attachments

  • Demo.zip
    14.7 KB · Views: 175
Upvote 0

Steve Miller

Active Member
Licensed User
Longtime User
Ok, understood. I'm still learning the ins and outs of B4A. I love it! Great work. Now, if only it were able to port the applications to the Microsoft Surface and Apple IOS. :)
 
Upvote 0
Top