I am trying to create a small Android App. The app will have four modes. The top part of the display will contain four buttons to switch between these modes, and this part of the display will not change. The rest of the display will change depending which button has been clicked on. It will contain a table with TextViews or images.
My questions are:
Is it possible to create the table layout programmatically?
How should I approach switching between modes:-
Four separate Activity classes?
One Activity and programmatically change the bottom part of it?
Should I create one base Activity with buttons and extend it?
What would be the best option?
Create layout by code is not the good solution. If your table layout is simple, I think it's not a big problem.
Here is a simple code how to create a layout by code :
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this);
layout.addView(new TextView(this));
setContentView(layout);
}
And as you see, it looks ugly !
Hope this help :)
#: Edit for additional question about Relative Layout:
In RelativeLayout (and some Layout of android), there is an object LayoutParamsto determine some properties of sub-layout (TextView, Button... is called sub-layout too if you put in other Layout)
Here is an example :
RelativeLayout layout = new RelativeLayout(this);
TextView textView = new TextView(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.FILL_PARENT);
params.addRule(RelativeLayout.BELOW, textView.getId());
layout.addView(textView, params);
You should notice BELOW, it is one of many int constant such as Right_of.... You can see on Android Document about these.
Related
After a lot of searching, I can not find a solution to my problem.
The summary of my program I ve also checked with a tabhost.
It's viewpager viewpager has fragmentpageradapter who get an instance vector fragments, the fragments will identified by their position in the vector.
The first fragment instantiates a listefragment using a simpleadapter.
The listfragment is loaded with json data oncreate.
In the GetView method of simpleadapter, I change a textview in one of the item using a button on the item and a textview which'm part of an instance of this fragmentactivity.
I have listfragment with different json given 4 different positions in my viewpager.
When I press the button on my item, my textview and change correct.
My problem
When I turn pages in my viewpager and I return to the previous page of my viewpager, all calls to this issue 0
My question
how to save and restore the state of the items in my listfragment?
Or do I make these?
My Attempts
Save and restore the fragment in my listfragment use a static method in the viewholder GetView of simpleadapter I'm turning around ............
Thanks
in advance for your help
After a week of research and have posted a question on this great forum.
I finally found my problem question.
Here is the solution
this.mViewPager = (ViewPager) super.findViewById(R.id.tabviewpager2);
this.mViewPager.setOffscreenPageLimit(this.mPagerAdapter.getCount());
Link stackoverflow
Saving Fragment state in ViewPager
link android
http://developer.android.com/reference/android/support/v4/view/ViewPager.html#setOffscreenPageLimit%28int%29
My requirement is to remove the title icons for all views but it seems impossible.
First i removed the references to the icons from extension point="org.eclipse.ui.views" in my plugin.xml file.
There is a similar question to this one where it is suggested to override getTitleImage() in the view that extends ViewPart so i did just that and i tryed 2 versions.
#Override
public Image getTitleImage() {
return null;
}
#Override
public Image getTitleImage() {
return new Image(getSite().getShell().getDisplay(), new Rectangle(0, 0, 1, 1));
}
The result no matter which method i used is that some views don't display the icon and some do. For example the first view is always opened without the icon but the following views get the default icon. Also if i have save and restore enabled and restart the application while leaving some views open, the one that is selected doesn't have the icon while the rest do.
This is so frustrating, i just don't get why something so simple has to be so complicated to implement.
I think the problem is views that have not yet been created (so getTitleImage has not been called). In that case the workbench part reference code uses the default image if there is nothing defined in the view definition.
If the above is correct creating an empty image icon file and defining that as the icon in the org.eclipse.ui.views extension in your plugin.xml should work.
I want to create a page like this:
My idea for bottom place is using monotouhc.Dialog by viewElement. But the question is this:
Is using monotouch for this the best way? or using tableview with datasource is better?
And if we should use monotouch.dialog how we can add this as a part of a viewcontroller?
You can do it either way.
I would personally create a set of custom elements: one for rendering the image, one for rendering the first bit of information, one for the second bit of information.
Then I would create the UI like this:
new RootElement ("House"){
new Section (){
new HouseImageViewElement (house_id),
},
new Section () {
new OverviewElement (house_id);
},
new Section () {
new DetailedElement (house_id);
}
In turn those elements should be built on top of reusable UIViews (see my blog post on patterns for UITableViewCells: http://tirania.org/monomac/archive/2011/Jan-18.html)
Which has the advantage that you can later use those elements elsewhere (for example to display houses in a list). It also lets you split the management of the layout in different parts of the code.
But you can also create an entire view that does that, and then host the view with a UIViewElement in MonoTouch.Dialog, or use it manually in a UITableView, or just display it manually.
I intend to build a web application where users can enter their time every week and have been struggling to get my head around the concept of a single page in GWT that gets repainted with data depending on the user actions. After researching a lot on this site and google, I found one link that I would like to emulate but dont know how to go about doing it in GWT. Although their source code is available, I dont think it is full and complete. I got some idea from this link - Multiple pages tutorial in Google Web Toolkit (GWT) but again dont know how to implement it into a working version. One small working sample would be great to help me understand and get started.
Could anyone please guide me as to how to achieve the look and feel of the screen with the link below and how the content can be repainted with data from the server ? Would I need to put all the logic in one EntryPoint class ? I would like to have the hyperlinks in the left navigation panel and show the content in the right panel. I seem to be completely lost after a few hours of research.
http://gwt.google.com/samples/Showcase/Showcase.html#!CwHyperlink
Thanks a lot for your help.
Regards,
Sonu.
A single page application layout is actually quite easy to achieve.
The first thing you do is define the general layout, using GWTs layout panels. For your layout, I'd suggest using a DockLayoutPanel.
Content content = new Content();
Button switchContent = new Button(content);
Navigation navigation = new Navigation();
navigation.add(switchContent);
DockLayoutPanel pageLayout = new DockLayoutPanel(Unit.EM);
p.addWest(new HTML(navigation), 7.5);
p.add(new HTML(content));
Here, the width of the navigation panel will be fixed, whereas the content will take the remaining space. You have to pass a reference of the button (or some other widget) which does the switch of the content area, add the button to the navigation area, and so on.
Put this into a class, e.g. called MasterPageFactory:
public class MasterPageFactory {
private MasterPageFactory() {}
public static MasterPage newInstance() {
Content content = new Content();
Button switchContent = new Button(content);
Navigation navigation = new Navigation();
navigation.add(switchContent);
DockLayoutPanel masterPage = new DockLayoutPanel(Unit.EM);
masterPage.addWest(new HTML(navigation), 7.5);
masterPage.add(new HTML(content));
return masterPage;
}
}
Now, in your EntryPoint class, call the factory:
RootLayoutPanel.get().add(MasterPageFactory.newInstance());
This example should get you an idea. Other options would be using a DI framework like Guice or the Command pattern.
Your question is mixing up a couple of concepts. If you want the user to click something that looks like a link, and in reponse the application sends a request to the server and shows a page that looks different than the page they're on, and that page has fresh data that just came from the server, then you want a perfectly normal anchor or form submit button. You don't need anything special or weird from GWT.
The showcase example you referenced lets the user click something that looks like a link, and looks like it loads a new page, even to the point of letting the back button work as expected, but does not actually hit the server to get a new page or new data.
In GXT, I've got a control with an important panel added to the bottom component, basically like this:
public class SamplePanel extends ContentPanel {
ContentPanel panel = new ContentPanel();
public SamplePanel() {
setBottomComponent(panel);
}
public void setVisible(boolean isVisible) {
panel.setVisible(isVisible);
}
The panel is being set as the "bottom component" because it needs to stay at the bottom of the widget and viewable at all times.
The problem is, while the visibility of the panel toggles correctly, the 'bottom component' area doesn't resize to become smaller and fit the new dimensions of the bottom area.
However, I've noticed that the bottom area does resize when I manually change the size of the widget with the mouse.
Is there any way to programatically force a redraw/repaint/re-layout... anything to have the bottom component change to reflect the new size of its contents?
I've tried all of these and they don't work:
public void setVisibility(boolean isVisible) {
panel.setVisible(isVisible);
doLayout(true);
recalculate();
repaint();
}
Thanks
In the last gxt you can do.
this.layout(true);
Otherwise you can fire an Events.Resize event.
I don't know about GXT, but in GWT I would use one of the force() or forceLayout() methods on my panel. Perhaps there is a similar API for doing that!
HTH.
Have you tried using the setLayoutOnChange() method of the ConentPanel?
I would suggest looking at this:
http://davidmaddison.blogspot.com/2008/12/gwt-rendering-process.html
What you can try to do is addListeners to the Panel and try calling panel.layout() there
This post claims that the top and bottom components to not participate in layout once the panel has been rendered and suggests a manual workaround (using RowLayout) or manually setting the size of the panel.
Consider finding the sizes from the parent and calling onResize(width, height)