Welcome to the CrackBerry Forums Create Your Account or Ask a Question Answers in 5 minutes - no registration required!
Results 1 to 23 of 23
Like Tree7Likes
  • 2 Post By peter9477
  • 1 Post By peter9477
  • 1 Post By peter9477
  • 1 Post By peter9477
  • 1 Post By Thunderbuck
  • 1 Post By peter9477
  1. Thunderbuck's Avatar

    Posts
    6,458 Posts
    Global Posts
    6,461 Global Posts
    PIN
    2B6927F7
    Thread AuthorThread Author   #1  

    Default Dynamically generated tabs?

    Musing about something...

    My first epic BB10 creation is a newsreader for a specific group of newsfeeds (I know, lame, but I've gotta walk before I run ). I had an idea, though, to maybe let the user decide which feeds he wants to see, and maybe even the order they're arranged in.

    There's a couple of ways I might go about it, but one idea that struck me was that of dynamically-generated tabs. Could a tabset be generated at run-time?
  2. peter9477's Avatar
    CrackBerry Genius of Geniuses

    Posts
    5,216 Posts
    Global Posts
    5,218 Global Posts
    #2  

    Default

    Yes, that's no real problem, and can be done several ways. If you're using QML only, you can define a Tab "template" in a ComponentDefinition, and clone them from there, inserting into the tab list as needed. There are even fancier techniques involving having Tabs without their own Panes. For example, you could use a single Pane that's reused for all Tabs, and send it signals to update the content as the user selects from your Tabs. This is probably what most people doing dynamic Tabs would probably do actually.

    Not aware of public samples offhand, but you can see all that in the docs and it's not hard to experiment and get it working.
    Battery Guru for BB10 tracks voltage, power, battery health. (Also on the PlayBook.) White Noise helps you sleep or concentrate.
    Follow us on Twitter or Facebook or visit Engenuity's mobile apps page.
  3. mikeo007's Avatar
    CrackBerry Genius

    Posts
    4,219 Posts
    Global Posts
    4,926 Global Posts
    #3  

    Default Dynamically generated tabs?

    Are you using webworks or cascades?
    Go get some apps!
    DocuShortcut - Free homescreen shortcuts(Built For BlackBerry)
    Symptom Journal - Track medical symptoms and causes (Built For BlackBerry)
    SkinEd for Minecraft - Create and share Minecraft skins
  4. bbquincar's Avatar
    CrackBerry Addict

    Posts
    528 Posts
    PIN
    2846D23F
    #4  

    Default

    peter9477 is correct that either of those would be good.
    I did or am doing one right now with 5 tabs. You don't see the lag with the dev but on the sim doing indviual panes becomes a load. My mistake was i have each tab loading on start up. so ComponentDefinition is the best way i think.
    BlackBerry for Life - Proud owner of the new BlackBerry Passport
  5. Thunderbuck's Avatar

    Posts
    6,458 Posts
    Global Posts
    6,461 Global Posts
    PIN
    2B6927F7
    Thread AuthorThread Author   #5  

    Default

    This is cool! Yes, I think I'll give this a shot; the maximum number a user would be able to have would be 6, so I don't think there'd be too much processing overhead.

    Thanks guys!!

    (PS thanks for the head's up on ComponentDefinition, bbquincar)
  6. peter9477's Avatar
    CrackBerry Genius of Geniuses

    Posts
    5,216 Posts
    Global Posts
    5,218 Global Posts
    #6  

    Default

    Just wanted to note that with the technique I describe, there's actually only one Page object, and it can be created statically (no dynamic needed) and simply shared amongst all the Tabs. The Tabs are created dynamically, but they're extremely lightweight (since they're not actually VisualNode objects) so there's not really any overhead associated with this. I've got an app where with my current data set I have 38 tabs and it loads as fast as when it had 1.
    Battery Guru for BB10 tracks voltage, power, battery health. (Also on the PlayBook.) White Noise helps you sleep or concentrate.
    Follow us on Twitter or Facebook or visit Engenuity's mobile apps page.
    bbquincar likes this.
  7. Thunderbuck's Avatar

    Posts
    6,458 Posts
    Global Posts
    6,461 Global Posts
    PIN
    2B6927F7
    Thread AuthorThread Author   #7  

    Default

    That sounds like a very cool approach, Peter.

    I'm not sure I get how that works, though. If the page itself is static, what is changing?
  8. peter9477's Avatar
    CrackBerry Genius of Geniuses

    Posts
    5,216 Posts
    Global Posts
    5,218 Global Posts
    #8  

    Default

    Quote Originally Posted by Thunderbuck View Post
    I'm not sure I get how that works, though. If the page itself is static, what is changing?
    The tab changes, and the Page can monitor the activeTab property on the TabbedPane, using a property binding, and update itself as appropriate.

    One way would be to add an onActiveTabChanged: handler in the TabbedPane, and call activePane.populate(some_data). Where "some_data" comes from is up to you...

    It's much like how ListView handles things with the visual items and the model data. It doesn't create one VisualNode (the things defined inside the ListItemComponents) per element in your DataModel. Rather it pre-creates as many as it can display at any one time, plus some extras to allow for responsiveness during scrolling (which it then caches). It gets the required data from the DataModel and updates the visual items. As you scroll, they get pulled off the screen and stored for later, and others are pulled out of storage and updated. If you scroll up and down through a long list, each visual node item is appearing and disappearing many times, each time with different contents that it has updated itself with when told to by the list.

    The TabbedPane approach described above is exactly the same idea, but with more manual work required. It's effectively like a ListView with a single visual node shown at a time, and none cached (because it doesn't need to), but as you "scroll" through (by selecting different tabs) it updates the same way.
    Battery Guru for BB10 tracks voltage, power, battery health. (Also on the PlayBook.) White Noise helps you sleep or concentrate.
    Follow us on Twitter or Facebook or visit Engenuity's mobile apps page.
    Thanked by:
    Thunderbuck (01-15-2013) 
    bbquincar likes this.
  9. bbquincar's Avatar
    CrackBerry Addict

    Posts
    528 Posts
    PIN
    2846D23F
    #9  

    Default

    Quote Originally Posted by peter9477 View Post
    The tab changes, and the Page can monitor the activeTab property on the TabbedPane, using a property binding, and update itself as appropriate.

    One way would be to add an onActiveTabChanged: handler in the TabbedPane, and call activePane.populate(some_data). Where "some_data" comes from is up to you...

    It's much like how ListView handles things with the visual items and the model data. It doesn't create one VisualNode (the things defined inside the ListItemComponents) per element in your DataModel. Rather it pre-creates as many as it can display at any one time, plus some extras to allow for responsiveness during scrolling (which it then caches). It gets the required data from the DataModel and updates the visual items. As you scroll, they get pulled off the screen and stored for later, and others are pulled out of storage and updated. If you scroll up and down through a long list, each visual node item is appearing and disappearing many times, each time with different contents that it has updated itself with when told to by the list.

    The TabbedPane approach described above is exactly the same idea, but with more manual work required. It's effectively like a ListView with a single visual node shown at a time, and none cached (because it doesn't need to), but as you "scroll" through (by selecting different tabs) it updates the same way.
    Can this all be done with out the use of C++ i hate C++ (also don't understand it that well). hope this can be achieved in qml without to much of a workaround needed.
    BlackBerry for Life - Proud owner of the new BlackBerry Passport
  10. Thunderbuck's Avatar

    Posts
    6,458 Posts
    Global Posts
    6,461 Global Posts
    PIN
    2B6927F7
    Thread AuthorThread Author   #10  

    Default

    I definitely like that approach, Peter. More efficient on all fronts.

    You are most helpful
  11. peter9477's Avatar
    CrackBerry Genius of Geniuses

    Posts
    5,216 Posts
    Global Posts
    5,218 Global Posts
    #11  

    Default

    Quote Originally Posted by bbquincar View Post
    Can this all be done with out the use of C++ i hate C++ (also don't understand it that well). hope this can be achieved in qml without to much of a workaround needed.
    I avoid C++ like the plague, and yes you can do all I described in QML and with JavaScript.
    Battery Guru for BB10 tracks voltage, power, battery health. (Also on the PlayBook.) White Noise helps you sleep or concentrate.
    Follow us on Twitter or Facebook or visit Engenuity's mobile apps page.
    Thanked by 2:
    bbquincar (01-15-2013),  Thunderbuck (01-15-2013) 
    Thunderbuck likes this.
  12. Thunderbuck's Avatar

    Posts
    6,458 Posts
    Global Posts
    6,461 Global Posts
    PIN
    2B6927F7
    Thread AuthorThread Author   #12  

    Default

    Was just re-reading this... it's like a horizontal scroller

    Just sitting down at the IDE to try to put this into practice. Thanks for the advice, Peter!
  13. Thunderbuck's Avatar

    Posts
    6,458 Posts
    Global Posts
    6,461 Global Posts
    PIN
    2B6927F7
    Thread AuthorThread Author   #13  

    Default

    So, I know we wanted to stay away from C++

    ...but I found this cool little XML reader idea. I think this is what I'll use to instantiate my tabs...

    The Bored Wookie :: BB10 Cascades: Populate a DropDown from an XML File
    bbquincar likes this.
  14. peter9477's Avatar
    CrackBerry Genius of Geniuses

    Posts
    5,216 Posts
    Global Posts
    5,218 Global Posts
    #14  

    Default

    Thunderbuck, you could also use a JSON data source and keep it all in QML if you want. It's only a few lines to set up the reader and load the data, then in an event handler in response to the load you just iterate over and process the items in JS code.
    Battery Guru for BB10 tracks voltage, power, battery health. (Also on the PlayBook.) White Noise helps you sleep or concentrate.
    Follow us on Twitter or Facebook or visit Engenuity's mobile apps page.
  15. bbquincar's Avatar
    CrackBerry Addict

    Posts
    528 Posts
    PIN
    2846D23F
    #15  

    Default

    Quote Originally Posted by Thunderbuck View Post
    So, I know we wanted to stay away from C++

    ...but I found this cool little XML reader idea. I think this is what I'll use to instantiate my tabs...

    The Bored Wookie :: BB10 Cascades: Populate a DropDown from an XML File
    For my new not released yet update of Launch Codes i used that site to get my dropdown boax and xml to work. Json would have been better i heard but i already had all mine xml files ready to go.
    BlackBerry for Life - Proud owner of the new BlackBerry Passport
  16. Thunderbuck's Avatar

    Posts
    6,458 Posts
    Global Posts
    6,461 Global Posts
    PIN
    2B6927F7
    Thread AuthorThread Author   #16  

    Default

    Quote Originally Posted by peter9477 View Post
    Thunderbuck, you could also use a JSON data source and keep it all in QML if you want. It's only a few lines to set up the reader and load the data, then in an event handler in response to the load you just iterate over and process the items in JS code.
    Here's what I'm stumbling on: I can get a page instantiated okay, but I don't get where I'm passing parameters to it
  17. peter9477's Avatar
    CrackBerry Genius of Geniuses

    Posts
    5,216 Posts
    Global Posts
    5,218 Global Posts
    #17  

    Default

    Pages don't seem to have useful signals that tell you when anything happens with them (open or closed) so you need to either use the signals NavigationPane has (e.g. onPopTransitionEnded) or in some cases, set up your own routines. When I push a Page, in my NavPane I always call page.opened() to tell it that it's open(ing) now. Then I just add "function opened(somedata) { ... } " and pass it whatever I want it to have. Or set up a custom signal to do that, and the Page connects to that in its onCreationCompleted. There's a handful of tricks... but maybe no "best practices" just yet.
    Battery Guru for BB10 tracks voltage, power, battery health. (Also on the PlayBook.) White Noise helps you sleep or concentrate.
    Follow us on Twitter or Facebook or visit Engenuity's mobile apps page.
  18. Thunderbuck's Avatar

    Posts
    6,458 Posts
    Global Posts
    6,461 Global Posts
    PIN
    2B6927F7
    Thread AuthorThread Author   #18  

    Default

    Quote Originally Posted by peter9477 View Post
    Pages don't seem to have useful signals that tell you when anything happens with them (open or closed) so you need to either use the signals NavigationPane has (e.g. onPopTransitionEnded) or in some cases, set up your own routines. When I push a Page, in my NavPane I always call page.opened() to tell it that it's open(ing) now. Then I just add "function opened(somedata) { ... } " and pass it whatever I want it to have. Or set up a custom signal to do that, and the Page connects to that in its onCreationCompleted. There's a handful of tricks... but maybe no "best practices" just yet.
    Yeah, and I'm guessing I can make some kind of QObject or QList I can pass as a parameter to load in whatever data I need to... I'm at my day job right now, but I'll get back to it tonight.

    I wanted to get into programming forever, and life kind of got in the way. Now it's dawning on me that if I start writing code on a regular basis that this might even become something of a hobby/business for me. I'd never expect this to support me in my retirement, but I'd have fun and maybe make beer money from time to time. My point is, I'm really just starting out when it comes to app programming, and it's great to find this kind of help.
  19. peter9477's Avatar
    CrackBerry Genius of Geniuses

    Posts
    5,216 Posts
    Global Posts
    5,218 Global Posts
    #19  

    Default

    Quote Originally Posted by Thunderbuck View Post
    My point is, I'm really just starting out when it comes to app programming, and it's great to find this kind of help.
    Not sure if you've checked out the BlackBerry developer support forums, but there's a whole lot of people there... including some RIM support from time to time (or when most needed). I tend to do the real support there, and don't check this forum so very often. There's also the now-very-active #blackberrydev IRC channel on Freenode, for realtime support.
    Battery Guru for BB10 tracks voltage, power, battery health. (Also on the PlayBook.) White Noise helps you sleep or concentrate.
    Follow us on Twitter or Facebook or visit Engenuity's mobile apps page.
    Thanked by:
    Thunderbuck (01-18-2013) 
    bbquincar likes this.
  20. TheStoof's Avatar
    CrackBerry Addict

    Posts
    696 Posts
    Global Posts
    701 Global Posts
    #20  

    Default Dynamically generated tabs?

    learning some c++ will help you do pretty neat things.

    i hate c++ too, but it isnt so bad once you test it out with bb10/cascades.

    Sent from my BlackBerry 9900 using Tapatalk
    Current phone: Q10/Nexus4
  21. Thunderbuck's Avatar

    Posts
    6,458 Posts
    Global Posts
    6,461 Global Posts
    PIN
    2B6927F7
    Thread AuthorThread Author   #21  

    Default

    Quote Originally Posted by peter9477 View Post
    Thunderbuck, you could also use a JSON data source and keep it all in QML if you want. It's only a few lines to set up the reader and load the data, then in an event handler in response to the load you just iterate over and process the items in JS code.
    Yes, JSON is looking like the more flexible way to go here. Especially since I've gotten a little more ambitious and decided I want to let the user build his/her own tab order; C++ could do that beautifully with XML, but JSON just looks more versatile in general.

    I'll let you all know how it goes. I'll definitely have at least one app to go in this weekend, but it's from the AppGenerator and that almost feels like cheating. I want to have one "real" app in by Monday to qualify for the LE...
  22. David in Durham's Avatar
    CrackBerry User

    Posts
    99 Posts
    #22  

    Default

    I avoid C++ like the plague
    Just out of curiosity, why all the hate for C++? I'm no longer in programming/developing, but I worked for years in C (and later in C++) and came to love them both. I have to admit that I prefer C because I've seen so many horrible examples of code-bloat in C++, but a well-designed C program is truly a thing of beauty.
  23. peter9477's Avatar
    CrackBerry Genius of Geniuses

    Posts
    5,216 Posts
    Global Posts
    5,218 Global Posts
    #23  

    Default

    Quote Originally Posted by David in Durham View Post
    Just out of curiosity, why all the hate for C++? I'm no longer in programming/developing, but I worked for years in C (and later in C++) and came to love them both. I have to admit that I prefer C because I've seen so many horrible examples of code-bloat in C++, but a well-designed C program is truly a thing of beauty.
    You quoted my words, but I didn't use the term "hate", bbquincar did.

    I like to think I'm practical about it to a large extent. It's not an irrational bias. I do almost all my coding in Python, whenever possible, for many different reasons. One is that I rarely have to type much "boilerplate" code, whereas Java and C++ are riddled with it. I probably type fewer than half the keystrokes to get a job done in Python than I would in C++. The code is shorter, more readable, and thereby easier to maintain. I don't have to futz with Momentics and other awkward (IMHO) IDEs but can stick with simple and easy-to-use tools like a basic text editor (for a decade that was SciTE, and lately I've been using Sublime Text 2 for most of the work). I can whip up command line tools to supplement my environment on the spur of the moment, without having to switch gears mentally all the time, since I use the same language. Automated testing is far easier (as with almost any dynamic language). Programs tend not to crash, but merely terminate with a nice stack traceback that shows exactly what the problem was, pointing to the specific line that failed. After getting really bummed out about programming a bit over a decade ago, encountering Python changed my attitude around completely and I've enjoyed it again ever since. Even when I have to work on non-Python projects, getting a periodic dose of Python (like to make a tool, as mentioned) is often enough to keep me from thinking life sucks. :-)

    There's also a familiarity thing. I first used C++ before there were many of the "newer" things that have been layered on top over the years, so they never sunk in well enough for me to really like them, as I was moving to other languages around that time. (Specifically, there were no templates nor namespaces way back then, in the dark ages.)

    I'm also a long-time C programmer, and even now when I'm working on these projects I do write some C++ code from time to time, as needed, to supplement the other stuff. Best is if you know many languages, and then you can be confident you're making a reasonable decision when you choose between them!

    Stray note, which will sound crazy to many but has excellent reasons behind it: my apps for BB10 combine C (sometimes), C++, JavaScript (with QML), and Python. I'm just preparing the graphing code for Battery Guru now, with Python driving OpenGL for the plot, and all the other code that's not directly UI-related is in Python.
    Battery Guru for BB10 tracks voltage, power, battery health. (Also on the PlayBook.) White Noise helps you sleep or concentrate.
    Follow us on Twitter or Facebook or visit Engenuity's mobile apps page.

Similar Threads

  1. How to Tab ....
    By Preytorion in forum Introductions
    Replies: 17
    Last Post: 10-16-2008, 11:42 AM
  2. webmessenger tabs?
    By jiffry1017 in forum BlackBerry OS Apps
    Replies: 1
    Last Post: 06-09-2008, 12:28 PM
  3. I'm A Second-Generation Crackberry Addict
    By Shyla.Marie in forum General BlackBerry Discussion
    Replies: 1
    Last Post: 06-04-2008, 02:25 PM
  4. the next generation...
    By kickinitlive247 in forum General BlackBerry Discussion
    Replies: 4
    Last Post: 05-01-2008, 10:43 AM
  5. Is the next generation BlackBerry a BlackBerry 8500?
    By MMB916 in forum News & Rumors
    Replies: 14
    Last Post: 03-28-2008, 10:44 AM

Posting Permissions