[Q] How to Reuse Fragments code with different values - Design, Prototyping, UI, Graphics

I have made two fragments. One is a list fragment and other is a details fragment. List Fragment shows the list of exams and when you click on an item in that list, details fragment shows its details. so now i want to use this same layout for different values. For ex- i have made this for all Law entrance exams and now i need to make for different exams like management, engineering,etc with the same layout (list+details) but with different corresponding values. Can anybody help me with this? or direct me to any sample code that i can look into?

Have you considered making an abstract class that extends the ListFragment, that has a method like protected abstract List<...> getList(), so that when you extend the class, the childen could "fill" the list with their own Lists. I don't know how your details fragment works, but it generally it should be the same. That should work

You want to make a custom subclass of Fragment and pass in the parameters that describe how that Fragment should be populated as arguments. The typical pattern for this is to use a static factory method in the style of "MyDetailsFragment.newInstance(Object arg1, Object arg2)".

Related

Size of Form

Hello,
i have an application, programmed in C#. I wanna that the size of the gui will automatically adapt to the size of the phone on which the application get used.
How can I do this?
In the Paint() event of the form examine its ClientSize property. This is the size of the client (White) area of the screen. It is itself a Size object with Height and Width integer properties, this.ClientSize.Width and this.ClientSize.Height
Use these values to position/resize your objects on the screen, by changing their Size and Location (Left and Top) properties, so that they fit in this area.
This event occurs before the Paint() event of the child objects, so they will be repositioned/resized before they themselves are drawn.
To be clever, reposition and resize screen objects, scaled to the screen size at run time, not values hardcoded at development time.
This technique can also detect a change of orientation, the values of Height and Width change over! If you want to be smart, handle this as well, and your app should be starting look pretty damned professional. A bit of work and it should look good on all screen sizes. Test them out against the SDK's emulator images for a range of device screen sizes.
The following code example positions the label in the correct place. Hey Diddle Diddle, slap bang in the middle!
Code:
private void Form1_Paint(object sender, PaintEventArgs e)
{
label1.Left = (this.ClientSize.Width - label1.Size.Width) / 2;
label1.Top = (this.ClientSize.Height - label1.Size.Height) / 2;
label1.Text = this.ClientSize.Width.ToString() + " x " + this.ClientSize.Height.ToString();
}
do you have to do this with every object you put on it? Seems like a lot of code. (also im doing this in VB so far..)
I'm afraid so. But it's worth the effort. Also it will run on all screen sizes, see image, and also the oddball ones they haven't thought of yet!
Change 'this.' to 'me.' and omit the C# end of line character ';' and it's now in VB.
Does your form property AutoScaleMode is set to AutoScaleMode.Dpi?
For controls set the anchor property (default is top|left) also to right (and/or bottom if needed). That will automatically 'stretch' the controls.
Advanced:
Now, if you really want to support different resolutions it will take much more work:
As already mentioned you have to rearrange the controls on orientation changes. Take a look at Developing Orientation and dpi Aware Applications for the .NET Compact Framework!
And finally you have to provide images in different resolutions.
Adapt to New Screen Orientations and Resolutions
Of course you have to decide if this is really needed for your app as this will take much more time.

Fragment vs Activity

Hey Guys,
I am thinking of an app where the screen has 2 parts. I am thinking of using fragments for this.
However here is my question:
In the first screen/activity I am asking a user to click something on the bottom half based on the question in the top half. Once the answer is correct the user goes to the next set of questions.
Example:
The first screen can have 2 half, on top pick colour black,and the bottom has 4 or 5 different colors. Once the user clicks black, I want the user to see the next question, Maybe, Pick color Red and so on and so forth.
My questions is should I be having one main activity and different fragments based on number of questions that I want to ask?
Also can I make a generic template for a fragment and use an array list to populate the contents of the fragements ?
Thanks
I would put all of them into one Activity, no Fragments are needed. Indeed, the app should be faster without Fragments.
For another question just change the text/color of the View at the bottom.
Your question cannot have a specific answer
If you could make a template (base) actvitity for all possible answers at the bottom part of the screen, why not adding the top part also
and make one template activity without fragments?
But i have a feeling that your app will benefit from fragments if you cant make the template above.
If all your answers are not so similar in UI or logic (for example colors, geometric drawings, ... songs played) then you need to
a) build on base answer activity used to communicate with the question activity (passing data etc)
b) build some ancestor activities for all possible answer types, and finally
c) populate an array of activity "types" (from ) and their parameters to load on the bottom fragment when needed
so you pick the next from the array.. make an instance of the activity based on its base class, pass the parameters and pass it on the fragment

[Q] 2 Questions about limiting the size of text in Zooper

I am making a spin-off of infobar, and I have it mostly working the want I want with two exceptions:
1) The weather string is usually fine, but in some cases it gets too large. Is there any way to get it to wrap to a specific bounding rectangle, or to shrink it if it gets past a certain length? Is there some way to test how long the string is? I don't want to use [tr], because I want to see the whole string.
2) Right now I am using [tr=0,25] to make sure the appointments don't overrun the box. I use [tr=0,25] instead of [tr=25] because I don't want the "..." for shorter strings. Is there some way to test the length of the string so I can only use the [tr] when I need to? That way I can get the "..." when it is appropriate. I tried using
$[tr=0,22]#C0TITLE#[tr]=#C0TITLE#?#C0TITLE#: [tr=22]#C0TITLE#[/tr]$
but the [tr=0,22]#C0TITLE#[tr]=#C0TITLE# always comes back as not equal.
Thanks.
mlkaufman said:
I am making a spin-off of infobar, and I have it mostly working the want I want with two exceptions:
1) The weather string is usually fine, but in some cases it gets too large. Is there any way to get it to wrap to a specific bounding rectangle, or to shrink it if it gets past a certain length? Is there some way to test how long the string is? I don't want to use [tr], because I want to see the whole string.
2) Right now I am using [tr=0,25] to make sure the appointments don't overrun the box. I use [tr=0,25] instead of [tr=25] because I don't want the "..." for shorter strings. Is there some way to test the length of the string so I can only use the [tr] when I need to? That way I can get the "..." when it is appropriate. I tried using
$[tr=0,22]#C0TITLE#[tr]=#C0TITLE#?#C0TITLE#: [tr=22]#C0TITLE#[/tr]$
but the [tr=0,22]#C0TITLE#[tr]=#C0TITLE# always comes back as not equal.
Thanks.
Click to expand...
Click to collapse
There is currently no way to test the length of a string in Zooper, sorry. As to the "wrap to a specific bounding rectangle", check out the X margin and Lines on a Rich Text Module The first defines the distance in pixels from the screen side when the text will break into additional lines. The second option sets into how many lines the text will break at maximum. Anything above that will be cut-off without an indicator like you get with the trim option. It's not exactly what you are looking for but I thought you might want another option to work with

[Q] ListAdapter error

I'm newbie at android development and I'm trying to build an app that have to show certain products but its divided in categories, and other subcategories, I'm showing in the first layout the categories and when I select any of them it have to show the next view where the orientation should be landscape 'cause I use a listview to show the subcategories in the left and a fragment to show their products in the rigth but I'm getting a nullpointerexception in the adapter set to the list
SebasEP6 said:
I'm newbie at android development and I'm trying to build an app that have to show certain products but its divided in categories, and other subcategories, I'm showing in the first layout the categories and when I select any of them it have to show the next view where the orientation should be landscape 'cause I use a listview to show the subcategories in the left and a fragment to show their products in the rigth but I'm getting a nullpointerexception in the adapter set to the list
Click to expand...
Click to collapse
It's easier to diagnose what your problem is with code and visual examples.
NullPointerException can be thrown in any number of scenarios. My guess is your adapter is pointing at a null object or no object at all.

Append variable width bitmaps dynamically so that resultant bitmap row is centered

I'm pretty sure what I'm trying to do is impossible with Zooper — I've experimented and searched massively — but maybe some wiz actually will know a workaround to what I'm trying to do:
I want to have a widget — which will place let's say two bitmaps side by side: they will be selected dynamically and their widths vary massively. I want the resultant “image”, consisting of the two images, centered: thus I can't put one left—aligned image next to one right—aligned, because the whole thing will not be centered.
I hoped the image field would let me specify two consecutive “” fields and I could nicely center this compound object — but it doesn't work, only displays the first image.
Is there a way to accomplish what I'm after, or is it truly impossible?
--
白い熊

Categories

Resources