how to pass value betweeen two tab in android
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());
精彩评论