I wanna display a TextView after say couple of seconds. No idea how to do it - android-activity

new to android and I don't know how to display a View after some time. I don't want codes, just want some guidance or resources so I can learn. Already googled it in vain.

You should use handler to post in UI thread . Then set time using postDelayed method of Handler class .
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
//Set the text in your textview here
}
}, TIME_IN_MILLISECONDS);

Related

GWT Bootstrap typeahead event listener?

I am using GWTBootstrap3 Typeahead widget. The main problem is the event is not getting deregistered and the events are bundling up as many times i load the component. The components are cached by default. The first component load triggers event 1 time and in second time component load triggers 2 times and so on. It's causing a lot of problem. I have tried HandlerRegistration and removeHandler() its not working. If any body found a solution please let me know.
Here is the bit of code where the event is registered:
HandlerRegistration typeAheadListener =
productSelect.addTypeaheadSelectedHandler(new TypeaheadSelectedHandler<Part>() {
#Override public void onSelected(TypeaheadSelectedEvent<Part> event) {
selectedPart = event.getSuggestion().getData(); // Handling the event
}
});
Thanks
I can think of two options there:
You can register the event handler in the productSelect's constructor, or in the code where you call the constructor. Not when the component is loaded.
You can check the HandlerRegistration API, it gives a tip on how a handler can deregister itself:
new MyHandler() {
HandlerRegistration reg = MyEvent.register(eventBus, this);
public void onMyThing(MyEvent event) {
/* do your thing * /
reg.removeHandler();
}
};

how to stop firing unrelated event of event bus

My problem is with how to stop firing unrelated event of event bus. as I got this solution for Dialog box.
but it does not work in case of where one instance already initialize and try to create new instance of same class.
Just example: A below scroll panel has handler initialized. it used for document preview.
class TestScroll extends ScrollPanel
{
public TestScroll(){
}
implemented onload()
{
// eventBus.addHandler code here.
//here some preview related code
}
unload() method
{
//eventBus remove handler code
}
}
This preview has some data which contains some links that open different preview but with same class and different data structure,
Now The problem is like onUnload ( which contains code of remove handler) event does not load , because other panel opened. that does not mean previous panel unload.
So in that case, twice event handler registered. when one event fired then other event also fired.
Due to that, Preview 1 data shows properly, but after that Preview2 opened and when I close it, I find Preview1=Preview2.
so how can I handle such situation?
As per no of instance created each event fired. but I have to check some unique document id with if condition in event itself.
is there any other ways to stop unrelated event firing?
Edit:
public class Gwteventbus implements EntryPoint {
int i=0;
#Override
public void onModuleLoad() {
TestApp panel=new TestApp();
Button button=new Button("Test Event");
button.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
TestApp panel=new TestApp();
int j=i;
new AppUtils().EVENT_BUS.fireEventFromSource(new AuthenticationEvent(),""+(j));
i++;
}
});
panel.add(button);
RootPanel.get().add(panel);
}
}
public class AppUtils {
public static EventBus EVENT_BUS = GWT.create(SimpleEventBus.class);
}
public class TestApp extends VerticalPanel{
String testString="";
public TestApp( ) {
AppUtils.EVENT_BUS.addHandler(AuthenticationEvent.TYPE, new AuthenticationEventHandler() {
#Override
public void onAuthenticationChanged(AuthenticationEvent authenticationEvent) {
System.out.println("helloworld"+authenticationEvent.getSource());
}
});
}
}
These are wild guesses as it's difficult to really answer it without code and a clear description.
I'm guessing you have one eventbus for all the panels. So when you register a handler it is registered with that one eventbus. In case you fire an event from one of the panels to the eventbus all panels will receive the event.
To fix this you can either create a new eventbus per panel or check who fired the event with event.getSource().
If this doesn't make sense you probably are reusing a variable or use a static variable which actually should be a new instance or none static variable.
You can use the GwtEventService-Library to fire specific events over a unique domain and every receiver that is registered at this domain receives that events then. You can handle as many different events/domains as you want.
In order to remove a handler attached to the EventBus, you must first store a reference to the HandlerRegistration returned by the addHandler method:
HandlerRegistration hr = eventBus.addHandler(new ClickHandler(){...});
Then you can remove the handler with the removeHandler method:
hr.removeHandler();
A final note worth mentioning is that when using singleton views, like is typical with MVP and GWT Activities and Places, it is best practice to make use of a ResettableEventBus. The eventBus passed to an activity's start() is just such a bus. When the ActivityManager stops the activity, it automatically removes all handlers attached to the ResettableEventBus.
I would strongly recommend reading the GWT Project's documentation on:
Activities and Places
Large scale application development and MVP

GWT MAP 3.8 (Google API) - Is onResize() needed to hide the "grey background"?

My problem:
- I display a map inside a popup and I have unloaded tiles (grey background).
- If I zoom out or in, then the map will fill the entire space (no grey background anymore).
My question:
- Have you any idea about my problem (Should I need to resize to hide the "grey background") ?
- I do not know if I should call onResize() inside the Runnable callback (code is above) or not ?
Thanks you,
My actual code: (I am using the javaxLoaderAPI)
// ENTRY POINT
GoogleMap map;
#UiField LayoutPanel gmap;
public void AjaxLoader_MAP() {
AjaxLoaderOptions options = AjaxLoaderOptions.newInstance();
options.setOtherParms("key=***&sensor=false&language=es");
Runnable callback = new Runnable() {
public void run() {
gmap.onResize(); // Should I call onResize() here ?
map = GoogleMap.create(gmap.getElement());
};
}
AjaxLoader.loadApi("maps", "3", callback, options);
}
May be related to the following post - GWT Google Map Api V3 - broken when changing it
I just posted an answer to that unanswered post as well. I believe it answers and sheds insight on this one as well.
I know this is an old post, but let me know if helps!
When calling mapWidget.triggerResize(), it's important to call it with some delay (Timer.schedule()) so that all the widget have been reset and then the map is resized.
This is how I trigger it:
#Override
protected void onReset() {
super.onReset();
Timer timer = new Timer() {
#Override
public void run() {
triggerResize();
}
};
timer.schedule(100);
}
Without timer, I was still getting grey tiles. Hope someone still finds it useful.

Timer Based Application In GWTP

I want to create a GWT application. That whenever the user gets logged in to system, it will show some information in PopUpPanel and after some time it gets disabled automatically.Is it possible with GWT ?
Could try something like:
Timer t = new Timer() {
#Override
public void run() {
popUpPanel.hide();
}
};
popUpPanel.show();
t.schedule(5000);
Where 5000 is how long you want to show the pop up for.

On click is not refreshing the tabledata

Hi I have been trying to reinitiate the data in a table by using an onClick handler
But when I click the data the older data persists and along with that the new data is coming up
Kindly let me know how can I resolve this issue
Thanks in advance
private void showErrorButton() {
//super.initWidget(widget);
_displayAlerts.addClickHandler(new ClickHandler() {
/**
* Click event for hiding dialog box.
*/
public void onClick(final ClickEvent arg0) {
getCustomDialog().getDialogBox().center();
getCustomDialog().getDialogBox().show();
showDialogBox(_errorList,_warnList);
}
});
}
It seems like you are not clearing the old data from your table before populating it with new data.
If you're using a Panel (GWT Javadoc) (or any subclass of Panel such as HTMLTable, FlexTable, etc.) you should call the method clear() before adding the new data.
void onClick(...) {
yourTable.clear();
yourTable.addNewData();
}
I'll change my answer as I learn more about your specific problem if this doesn't help.