如何在Android中的两个选项卡之间传递值 [英] how to pass value betweeen two tab in android
问题描述
我已经按照android标签主机指南进行操作,并且能够在模拟器上运行.现在,我要做的就是在一个tabview中实现一个文本框和一个按钮.一旦用户在文本框中输入并按下按钮,在文本框中输入的值就会传递到第二个选项卡,我可以将该值用于进一步的计算.
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());
这篇关于如何在Android中的两个选项卡之间传递值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!