how to pass value betweeen two tab in android - android-tabhost

I have followed the tutorial for android tab host and been able to run on emulator. Now what I want to do is just implement a text box and button in one tabview. As soon as user enter in text box and press button the value entered in text box shouls pass to second tab and I can use that value for further calculations.
Please guide me how to do this?
Thanks,
Alok.

I think what you should to do is to declare a global variable:
class foobarApp extends Application {
private String txtValue;
public String getTxtValue(){
return txtValue;
}
public void setTxtValue(String aString){
txtValue= aString;
}
}
So, when the user presses the button:
foobarApp myApp = ((foobarApp)getApplicationContext());
setTxtValue(myTextEdit.getText());
And then, when the second tab loaded, you can get your value by doing this:
foobarApp myApp = ((foobarApp)getApplicationContext());
theOtherEditText.setText(myApp.getTxtValue());

Related

How to lock Form during lunch a class?

I have a simple Form MyCustomForm, in a Form's Button in Clicked method I call a Class (method run), so I want to lock (or block) this form during run execution.
My code is look like this :
void clicked()
{// in Button clicked in **MyCustomForm**
MyClass myClass;
super();
myClass = new MyClass();
// here I want to freeze my FORM
myClass.run();
// here I want to unlock my Form
}
I need this because when class (MyClass) is running can display Dialog etc, but I don't want to touc/click and other on MyCustomForm
If I use :
element.wait(); // not work well - block all
myClass.run();
Thanks,
enjoy.
If your class displays dialog you can make this dialog modal using the following line of code dialog.parmIsModal(true).
Or formRun.wait(true) for forms.

How to get the gameobject- which triggered the UI.Button click function

in Unity 5- I am trying to disable a ui.button- once it is clicked. There is a list of buttons- among which- the clicked one will be disabled. But I am not sure, if it is possible to get the event triggering gameobject.
Unity Editor-
Code:
// called from ui.button clicks
public void callThisMethod(string param) {
// how to get the clicked button gameobject here
}
Just Add another event to return the button
public Button ButtonPressed(Button ThisButton)
{
return ThisButton;
}
You can add something like this to your code:
public Button yourButton;
public void yourButtonClicked(){
yourButton.interactable = false;
}
Assign your button to the Button object in inspector. Then where it says "On Click()" in the image you have above, select the script the above code is added to, and select the "yourButtonClicked()" function. That will disable the button once it is clicked.
To get your clicked button game object, you can use: EventSystem.current.currentSelectedGameObject
Pass the gameObject of the button as a parameter while your are adding event listener to the UI button.
Hope that helps:
GameObject myButtonGameObject = myButton.gameObject;
myButton.onClick.AddListener(() => {LogName(myButtonGameObject); });
public void LogName(GameObject buttonGameObject = null){
Debug.Log(myButtonGameObject);
}
Note: The given approach is useful, when you need to dynamically show the clicked buttons name, but if you know the exact button, you can make a public field for the myButton and get the name without passing any parameters.

Editable Label/Div losing focus on click

I have an editable GWT Label which shows a strange behavior. That is if I click the text “Add note…” the cursor does not appear until I click a second time. But if I click on the label outside the text the cursor appears on first click. How do I solve that? My guess is that replacing the text also removes the cursor when the cursor is in the text. So how can I get the cursor back on first click?
public class EditableLabel extends Label implements FocusHandler {
public EditableLabel() {
super();
getElement().setAttribute("contenteditable", "true");
getElement().setAttribute("tabindex", "1");
this.sinkEvents(Event.ONBLUR);
this.sinkEvents(Event.ONFOCUS);
addHandler(this, FocusEvent.getType());
setText("Add note...");
}
#Override
public void onFocus(FocusEvent event) {
setText("");
}
}
I think your problem depends on the browser. On FF it works fine for me.
I assume you want to write something, if so try to change Label for TextBox, it should work.

GWT, disable autoclose MenuBar when clicking on MenuItem?

I want to if it is possible to disable the auto-close MenuBar when I click on a MenuItem?
I have several MenuItem that are like checkboxes, so I can check more than one MenuItem and don't want my menu close everytime I checked one.
Thanks.
I was facing same problem and I will share with you my solution:
1) Create new class MyMenuItemWithCheckBox that extends the MenuItem.
In the constructor set element ID to (forexample) menuItemWIthCheckBox + Unique text.
this.getElement().setId("menuItemWithCheckBox_" + menuItemLabel);
2) Create new class MyMenuBar that extends the MenuBar.
Override the onBrowserEvent method by following:
Override
public void onBrowserEvent(Event event) {
if (DOM.eventGetType(event) == Event.ONCLICK && getSelectedItem().getElement().getId().contains("CheckBox")) {
Scheduler.get().scheduleFinally(new Scheduler.ScheduledCommand() {
#Override
public void execute() {
getSelectedItem().getScheduledCommand().execute();
}
});
event.stopPropagation();
} else {
super.onBrowserEvent(event);
}
}
Now scheduled command of MenuItem is always called, but in the case of your
menu checkBox item there is no close of a menubar.
I hope this help you, I spend more than day to create this solution. :-)
First, directly it's not possible because the popup-panel which displays the submenu is private in the MenuBar class.
Buuut, there is a way to do so ...
Simpley fetch the current MenuBar.java code out of googles code repository and include it in your eclipse gwt-project.
You don't have to change anything e.g. package deklaration or something. Just put your source in your project and it will simply replace the original MenuBar-class from the gwt-sdk during compilation (works also with hosted development mode).
Then you can simply set the property autoHide of the popup-Panel to false and the popup shouldn't disappear after clicking.
You can set hideOnClick to false on the menuItems
See here.

Open contact activity when a specified input-field is pressed

I want to launch an contact-activity when a input-field (text) in a webview is pressed. Not sure how I can do this. Have tried to search the web but the only results I get is how to launch a filebrowser when a "input-file-field" is pressed.. And it seems like Android have an option that is exactly for that purpose, but not when another input-type is pressed?
What I actually want to do is;
when the input field is pressed, I want to give the user an option to launch the contact manager (or something similar) to choose one or more contacts from its contactlist.
Then fill the input-field with the contacts emails, separated with commas.
Is it possible to do this? Any idea what I should search the web for?
Solved! Added a new class:
import android.content.Context;
import android.content.Intent;
public class JSFromPage {
Context mContext;
JSFromPage(Context c) {
mContext = c;
}
public void openContact() {
Intent intent = (Intent) new Intent( mContext, ListContacts.class );
mContext.startActivity( intent );
}
}
And uses this is my WebView class:
mWebView.addJavascriptInterface(new JSFromPage(this), "Android");
And this is my html on the input:
onclick="Android.openContact();"
Then i created the class "ListContacts.class" with a new activity.