how to pass value betweeen two tab in android

荒凉一梦 提交于 2019-12-01 11:18:29

问题


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.


回答1:


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());


来源:https://stackoverflow.com/questions/5231383/how-to-pass-value-betweeen-two-tab-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!