how to pass value betweeen two tab in android

大城市里の小女人 提交于 2019-12-01 12:48:25

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