Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 6    Views: 66

Don
Aspiring developer
Profile
Posts: 40
Reg: Aug 10, 2012
moving within e...
2,550
09/24/12 02:03 AM (13 years ago)

Custom button to load a BT_screen

Hey all, I am coding an android application with BT v2 On a BT_screen, I am using some custom buttons that I have manually added into my source code directly via Eclipse. When the button is pushed, how can I call another existing BT_screen (with its id defined in the config file like any other BT_screen) from this button? I am trying with a onClickListener (see below) but I am a bit lost. Button mybutton = (Button) findViewById(R.id.mybutton); mybutton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent i = new Intent(); i.setClassName("com.myapp", "com.myapp.mynewscreen"); startActivity(i); } }); This calling method works fine when I call a static screen, but not when I call a dynamic screen such as a listmenu item Any idea how could this button call a dynamic screen such as a listmenu BT item? Thanks
 
Rishav
Code is Art
Profile
Posts: 153
Reg: Jan 26, 2012
Dubai
8,780
like
09/25/12 12:09 AM (13 years ago)
I am also stuck in the same thing. I had a similar question earlier but didn't got any replies.
 
Don
Aspiring developer
Profile
Posts: 40
Reg: Aug 10, 2012
moving within e...
2,550
like
09/25/12 12:42 AM (13 years ago)
Hey elecy, thanks for sharing this. At the moment I am leaning towards a solution where I still use my custom button but don't load a bt menu list, I would load a custom list instead. Pretty ugly but would allow me to go exactly where I want
 
Don
Aspiring developer
Profile
Posts: 40
Reg: Aug 10, 2012
moving within e...
2,550
like
09/25/12 07:31 AM (13 years ago)
Answering to myself, hopefully it can help the community: All right, guys, this is probably a very ugly solution but it seems to work. Please feel free to tell me if this is a dangerous method or if it could break something, really interested in that. 1) PASS YOUR BT PARAMETERS VIA A CUSTOM BUTTON (MEANING A BUTTON YOU HAVE MANUALLY ADDED IN THE CODE, NOT COMING FROM A BT SCREEN) Button code: Button bmore= (Button) findViewById(R.id.bmore); bmore.setOnClickListener(new OnClickListener() { public void onClick(View v) { tapMenuItemObject = new BT_item(); //the item type below is a new class I have manually added to my app, based on the BT blank screen tapMenuItemObject.setItemType("BT_screen_more"); tapScreenLoadObject = <myappname>_appDelegate.rootApp.getScreenDataByItemId("55555"); //call loadScreenObject (static method in this class)... BT_act_controller.loadScreenObject(thisActivity, screenData, tapMenuItemObject, tapScreenLoadObject); } }); 2) IN THE JSON FILE: // Here is an example of a set of parameters for my item with id 55555. Here I only need the parameters of the navbar, so I only wrote the necessary parameters. I could have added more parameters if I wanted to load a more advanced screen. For Example I could add here the child items of a BT menu list screen if my button called a custom MENU list... {"itemId":"55555", "itemType":"BT_screen_more", "itemNickname":"nickmore", "navBarTitleText":"Options", "navBarRightButtonType":"home", "navBarRightButtonTapLoadScreenNickname":"Menu", "navBarRightButtonTapLoadScreenItemId":"83428AE16476046D91BF786"} Hope it helps, and once again, probably dirty code, as I am really not a java expert. Please feel free to let me know if there is a better solution or if this one could have undesired collateral damages :)
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
09/26/12 12:36 AM (13 years ago)
@Don: good work! I saw your other post a few minutes ago and it pointed to this one. It's all about understanding what the static method: loadScreenObject() expects as arguments. //here's the method stuf... public static void loadScreenObject(Activity parentActivity, BT_item parentScreenData, BT_item theMenuItemData, BT_item theScreenData) 1: parentActivity: This is the Activity that is currently being displayed. In other words, the screen the button is on (in your case). 2: parentScreenData: This is an instance of the BT_item that represents the data for the currently beging displayed Activity. This is the same screen as above, the one the button is on. In most cases, you'll pass this.screenData as the argument. Every screen has it's screenData property set when the screen loads. 3: theMenuItemData: This is the data that represents the "row" or "button" item that was tapped. You can pass null here. The idea is that rows and buttons may contain data that's not related to the screen that's loading (like a sound effect or other advanced things). 4: theScreenData: This is the data that represents the "next screen" to load. In most cases you'll create a new screen to load with the getScreenDataByItemId static method. Like... BT_item nextScreen = <myappname>_appDelegate.rootApp.getScreenDataByItemId("55555"); Summary...in most cases all you need to do is to create this "next screen" object because all the other objects are already created. Something like this: //create a new screen object to load... BT_item nextScreen = <myappname>_appDelegate.rootApp.getScreenDataByItemId("55555"); //show the next screen using the static loadScreenObjectMethod() in the BT_act_controller class. "this" represents the currently displayed activity. BT_act_controller.loadScreenObject(this, this.screenData, null, nextScreen); That should do it.
 
Don
Aspiring developer
Profile
Posts: 40
Reg: Aug 10, 2012
moving within e...
2,550
like
09/26/12 01:25 AM (13 years ago)
Thanks a lot for all these details David, very useful! So from your answer it seems I haven't broken too much collateral stuff with my dirty solution haha! I hope it's ok with you when users like me change your code. And that you don't feel invaded or concerned! I have to admit, I am a bit of a customization maniac (too much says my girlfriend) so I want to customize everything :) But it is so much easier to start from a great framework as BT is, especially when you are no programing expert (that is me)
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
09/26/12 02:15 AM (13 years ago)
Hi again...2:00 AM on the West Coast, preparing for an early morning meetup in the UK. I'll be Skyping in. Good stuff. We EXPECT you to change all this code, we really do. That's sort of the whole idea. Hack it, improve it, publish it, sell it! Cheers.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.