In my Vaadin 8 application, I have a TabSheet, that contains several views. When I override the enter method in the first view of my TabSheet, and then I proceed to enter the view on my application, the method doesn't get called.
Do you have a Navigator, and have you registered the views for it? Navigator's navigateTo is what calls the enter. Registering views happens along these lines:
navigator.addView("", new InitialView());
navigator.addView("second", new SecondView());
Navigation also updates the URI fragment in your browser, and makes it possible to bookmark specific views and enter them via direct URL. See e.g. https://vaadin.com/docs/v8/framework/advanced/advanced-navigator for more information about Navigator.
TabSheet isn't the most trivial thing to use with Navigator and I'm afraid I don't have a ready-made example at hand, but I think it should be doable with a custom ViewDisplay and maybe SelectedTabChangeListener.
If you aren't interested in the Navigator approach, I suppose you could replace the View+enter with something along these lines, although if you need to know the previously selected tab you'll need to keep track of it yourself since this particular event isn't very informative:
tabSheet.addSelectedTabChangeListener(e -> {
((MyClass) tabSheet.getSelectedTab()).myMethod());
});
Related
After a lot of time spent I can't find the solution. I want a button or any clickable view should stay visible for all activities and it should be only for one specific app not like chat heads. I am basically making a library so that's why I can't use base activity.I have attached the image as well for a better explanation. How can I achieve this any suggestions? thankyou...
I
It sounds like you need a ViewOverlay. This is the API documentation.
ViewOverlay is usually tied to a single view, but if you wrap it in a fragment, you should be able to attach it to each view in your application. This should create the effect of an of an application scoped overlay.
There may be a more elegant way of doing this, but I am not aware of it.
EDIT: You can also wrap your layouts inside a frame layout(s) along with a seperate nested view (the view that you want to keep on top of the stack).
Frame layout creates a 'stack' of inner views. If you use this approach, you can programmatically ensure that there are exactly two views present and visible as children of your frame layout at all times. one will be the layout tied to your current activity. The other will be the view that you want to be overlayed.
I know that the term 'programmatically ensure' is vague. This is because there are many ways to make this happen. It is up to you to decide which way best suits your needs.
Despite its not best UX. I wonder what is the best solution to start several different Activity(Dialog) with different callback implementation. I assume starting each dialog needs to be from static fabric method with context.startactivity(dialog1). Each dialog looks exactly the same besides some title and message but callback for ok and cancel buttons are different. I want to separate implementation of dialog callbacks(ok, cancel) from generic dialog behavior. What if I can't pass actions while starting activity from static method, I don't find Bundle to fit this case.
How about this, create an enum for the dialogs.
Based on the enum you can either have the values for everything be in the enum itself or switch on the enum in your code at the appropriate places.
recommend creating different click listeners for the yes and no buttons.
In those click listeners you can switch(enum) and for each case have the specific business logic. OR create different click listeners and use a factory that will allocate the listeners based on the enum.
either solution works depending on how you want to code it. They both have their own pros and cons.
There is an AlertDialog.Builder class that you may be able to use depending on what your dialogs look like. There is also the dialogfragment class that you can extend to help out with the dialogs.
if you want to show the users several dialogs you will need some sort of queue that you populate with all the dialogs that you want to show and then show them one after another, IMHO, use different views and just replace the view in an activity so you can slide it in or animate it in somehow.
You can make them look like cards and then just change the text inbetween that way switching on the clicklisteners based on the type of the current view will be easy and you can even have the enums provide the views using the R.layout.layout_name as a value in the enum.
I know that is a lot and maybe some of it is unclear, Please ask questions and i will do my best to respond in a timely manner.
I have a app on Google App Engine and I'm using GWT, and when the user goes to www.myapp.com/#show I need to show a graph, and in that page there is a button to search and add nodes to that graph, when the search Button is clicked I need to show a popup with the search form (it has several functions and dialogs).
Can I create a view for that page and another view for the popup and use the same presenter for both?
or What is the best way to implement that based on the pattern MVP?
MVC(Model View Controller) style tells that you have this three packages for Entities, UI, Controller classes. This help you organize your code and break it to plugins.
As for your question it is better if you can implement a CustomPopUp class in the View(UI) package and make it abstact. So PopUp could have as parameters the message the context or everything it needs to show the approprate message.
And you can pass CustomPopUp as private delegator to your UI classes who need to show popup messages.
I want to develop an Android app, where start page of the app GUI, will contain 4 vertical layouts in the main layout. Now, in each layout, I want to add buttons/slider dynamically from the app (instead of adding buttons/slider dynamically in the source code). That means, initially all these 4 layouts will be blank and when user will select any button or slider in another layout, to add it in any of this 4 layouts, the button or slider will be added in that layout. User will be able to add max 10 views in any vertical layout and the views can be either button, slider or custom view.
My attempt:
First I tried to create 4 vertical layout under the main layout for startup page and I got succeed.
I also find after searching that its possible to add views dynamically in layouts in android.
dynamically adding a view to activity layout
But most examples, add views dynamically in android by running loops, instantiating the desired view class and then add it in the main layout. Although, in this way, views are added dynamically in the layout, it is done by modifying the source code.
Is it possible to write the source code in a way, so that it can be done directly from the app? So that when user will click on Add a slider in "layout 1", a slider will be added in layout 1 and then again, when the user will click on "Add a button" in layout 1, a button will be added at the end of the slider. User will be able to customize button or slider properties. Also, if the user change the value of the slider, the app will remember its value.
Now, next time, when the app will be opened, those views will be there in the layouts, they will not be deleted and the values will remain unchanged (for example, a ticked check box will remain ticked), so I think I also need some kind of storage or properties manager.
My question is, is it possible to do this in android (because I never seen such apps in android) and if possible, any idea, how can I implement it?
I am totally new to android, so my knowledge is limited but I completed the basic tutorials on android app development and I have plugin development experience in eclipse.
Thanks a lot in. I will highly appreciate your help.
Of course it is possible:
Every layout (like LinearLayout, RelativeLayout etc.) extends the ViewGroup-class, which offers the addView-method.
To add a new view (like a Slider) to one of your layouts, just instantiate it programmatically (via new) in your activity and assign the appropriate LayoutParams to it
To store the state of user added content, it is the easiest to use SharedPreferences - a simple key-value-store which holds data over the application's lifecycle
Yes. This is possible. To create the Views dynamically, you simply have to either extend the class of the View or just say new Button(Context, AttributeSet); (Not only for Button's every View has a constructor that takes an attribute set and a context).
Using Layout.addView() you can add any View to the Layout.
Using SharedPreferences you can indicate what View belongs in what Layout.
If you decide to extend the View's class, make sure not to do too much in it. I tried that once and it just gave me an OOM (OutOfMemory Error) because I had a ton a Views trying to do stuff at the same time.
Right now I have a specific group of UI elements(Spinners, edit-boxes, buttons, etc.) which I want to be in the program's UI multiple times. Specifically one copy when the program first loads up and new copies are 'created' and show up in the UI due to user interaction(such as a button press event). I'm aware of using XML to define a specific UI groups but I'm not sure how to properly set up having those groups appear in the UI at the start of the program and by user command within the Java code.
This should be a good idea implements it group of components as a View subclass, this way you view going to comport as a stand-alone component and ready to re-use.
You can still make the layout.xml to it view, inflate it into the onCreate and assign the behaviour of actions in the components of this group.