How to create "levels" in Marmalade? - android

I would like to create a game with Marmalade, but I don't know how to make "levels" in it. I mean levels, as on Android the screens, or the activitys.
For example I don't know how to make a menu, then click on a button (I can make the button, control the touch...) and create a fully new screen for a game level.
On Android there are Activitys for this reason, but how can I do it in Marmalade?

You can use marmalade's IwUI api for this. It is used for creating the UI of the game. You can either use .ui files (similar to xml files in android/xib in iOS) or can do it programmatically too.
What you need to do is, create separate CIwUIElement* objects which can represent complete views in your game. These can be called as you main page elements or super parent elements. You can assign childs to those super parents, such as buttons, images etc.
According to button clicks you can add or remove these super parents to the IwUIController and change the views according to that. You can add the elements without removing previous ones, which will result in an overlay.
You might want to create separate class for separate Super Parent element. I've created a base class for UI and subclasses to hold super parent elements. These subclasses works as an activity for me and instead of calling intent, I do add or remove them from IwUIViewController

Related

Android Studio Single activity acting as many

I have looked everywhere but don't seem to be able to find what I am looking for. I have an activity with multiple buttons, each button opens a new activity with an identical recyclerview layout, but different data. I am wondering if it is possible to use one activity and layout instead of multiple? this way instead of having 10+ activities (one for each button) I only have to manage one when a button is clicked and simply pass the necessary list data to it.
I believe you could set the intents for each button to call the same activity but with an integer such as 1-10, in the activity it takes the value and decides which list should be presented? If anyone thinks of how this could be done or a simpler way I would greatly appreciate it!
Yes, there are various ways to do that.
You could use multiple fragments on the same activity. Then add/remove fragments on each button click.
You can have multiple layouts within your activity. Say you have two buttons, and you have three layouts layout1, layout2, layout3, sequentially one after the another. So if initially, layout1 is visible and the rest are gone using layout.setVisiblity(View.GONE), if you click button1, ypu can do layout1.setVisiblity(View.GONE); layout3.setVisiblity(View.GONE); layout2.setVisiblity(View.VISIBLE) and vice-versa for pressing button2.
Are all the activities opened by the buttons similar? If so, you could only take care of the changes in the elements of the layout & specify conditions.
For instance, if you click a button, instead of changing the whole thing, you only go into the buttons & change their texts with btn.setText("..."). You could define different conditional statements inside the onClickListener of that button.
It could be something like:
if(btn.getText().equals("a certain text that you set to the button")){
doSomething();
else if(btn.getText().equals("another option")){
doSomethingElse();
Following this logic, you could continually update the elements in your layout & your code will decide what to do depending on what's stored in these elements.
The second option that comes to my mind would be creating different xml layout files & simply changing the layout of your MainActivity to the appropriate one depending on what stage of your process you are at.
I hope this helps,

Fragment vs Activity with LinearLayout in Android

I have a dynamic UI that I need to generate and I would like to know what the best approach would be to do this and why? The application that I need to make will either way only have a single activity in which to display various different views which are generated by code, so not in an XML file.
So basically I want to draw one set of views and have a user interact with them (textview, button, radio button, edittexts etc). Then save the data he generated, clear the canvas or screen and within the same activity generate the next set of views for the user to interact with.
I have done extensive research and I know that I can use either a Fragment or an Activity with a LinearLayout to achieve this, but I am not sure which would be better and why?
Thanks,
Wihan

accessing layout.xml through java and assigning values to views in android

I am new to android programming am trying to learn it.
So basically there are two ways of creating whatever is going to be visible on the screen :-
We create views and view group objects inside layout.xml files. And then as the need be we access those views that are already existing
in the layout through our java programs by accessing their ids ( as
r.java….). So basically when we start a particular activity, we
set the content to be displayed corresponding to that activity using
setContentView method, to which we pass the layout.xml file, inside
which we have defined the different views and view groups to be
displayed on the screen.
The second way is we create these views dynamically though our java programs and then set them as the content on the screen using
setContentView again.
Now the above is my basic understanding. Please let me know if the above needs correction.
Now what I want to understand here is :-
Is there a way that using the first method itself, we can do the
vice-versa, as in say instead of fetching the the views through their
ids from the layout.xml files, can we already have a predefined
layout.xml file with different views having ids, and now through our
java programs can we just access those views though their ids and set
their values, something like say (in javascript) :-
document.getElementById(“someTextBoxId”).value= “some calculated
value from java code here”
Thanks.

How to list all dynamically created views in an activity?

I'd like to see all the dynamically created Buttons, TextViews, etc before (or even after) setContentView() shows them on the screen. I have a loose understanding that this relates to the Context and the Activity, but concretely I don't know where these dynamic views exist / how they are put together at runtime.
And if they are shown at runtime is there a way to list all of them?
LinearLayout layout = new LinearLayout(this);
layout.addView(button1);
layout.addView(button2);
layout.addView(button3);
setContentView(layout);
The buttons SHOULD exist somewhere (I am so sure they exist in the Context!!) but there is no way (that I have found) of locating these dynamically created views.
Please and thanks.
In general, if you are going to need to display these kinds of things on the screen, then you should keep a reference to them somewhere. This is a common pattern, if you dynamically create a button, you need to stuff them in a List (for example). You shouldn't need to get all the views if you program like this, and even if you easily could (typically in GUIs, you can, either by reflection, or something equally tacky mechanism) it wouldn't be organized in any kind of logical structure that would relate the things in the layout to the logical layout dictated by the application. So instead, when you dynamically create views, stuff them somewhere like a list so you can iterate through it later.

listview reusable component - architecture - android

i have a complex view which contains 4 list views arranged as per the requirement. i have been been able to implement and get it working. but this is a sole activity and data needs to supplied internally (within the activity).
i want to define a way where in, this complex view is like a reusable component which is called by other activities that provide data for all 4 list views and then the view shows up in the screen.
could somebody please guide me as to how do i go about achieving this functionality.
You should define your listview structure in a layout file of its own. Then you can use whats called inflation, which lets you "inject" seperate layout files into your main layout in run-time. Take a look at:
http://developer.android.com/reference/android/view/LayoutInflater.html
Take note at the introductory notes. Android is already inflating an XML resource, namely the layout file you´ve defined in setContentView(), you can grab the current instance of the inflater and use it as you see fit, saving greatly on memory as opposed to instantiating it yourself.

Categories

Resources