单击按钮时从 TabActivity 启动的 Activity 中调用自定义方法
我在我的主 TabActivity 中创建了 4 个活动意图(我将其添加到 TabHost)。我还有带有 onClick 方法的按钮。单击此按钮后,我会在 Rezultati 活动的意图中添加一些额外内容。现在我尝试从此 TabActivity 调用已启动活动的自定义方法来使用该附加功能。
以下是创建意图之一的示例:
public class Prvi extends TabActivity {
public Intent rezultati;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
rezultati = new Intent().setClass(this, Rezultati.class);
spec = tabHost.newTabSpec("rez").setIndicator("Rezultati",
res.getDrawable(R.layout.novice))
.setContent(rezultati);
tabHost.addTab(spec); }
在按钮上单击此方法被调用:
public void isci(View view)
{
EditText iskano = (EditText) findViewById(R.id.iskano);
rezultati.putExtra("Iskano", iskano.getText().toString()); }
现在我有类 Rezultati.class,我想在其中调用方法更新:
public class Rezultati extends Activity{
{
public void update(){
String value = getIntent().getExtras().getString("Iskano");
TextView textview = new TextView(this);
textview.setText(value);
setContentView(textview);}
}
我尝试在函数 isci(View view) 中创建类 Rezultati 的新实例并调用函数 update
Rezultati r=new Rezultati();
r.update();
除非当我调用 r.update() 时更新函数中没有任何内容,否则它会起作用,否则每次都会停止工作。
我做错了什么?
I creat 4 intents of activities(which i add to TabHost) in my main TabActivity. I also have button with onClick method. When this button is clicked i put some extras in intent of activity Rezultati. Now i am trying to call custom method of started activity from this TabActivity to use that extras.
Here is example of creating one of the intents:
public class Prvi extends TabActivity {
public Intent rezultati;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
rezultati = new Intent().setClass(this, Rezultati.class);
spec = tabHost.newTabSpec("rez").setIndicator("Rezultati",
res.getDrawable(R.layout.novice))
.setContent(rezultati);
tabHost.addTab(spec); }
On button click this method is called:
public void isci(View view)
{
EditText iskano = (EditText) findViewById(R.id.iskano);
rezultati.putExtra("Iskano", iskano.getText().toString()); }
Now i Have class Rezultati.class where i would like to call method update:
public class Rezultati extends Activity{
{
public void update(){
String value = getIntent().getExtras().getString("Iskano");
TextView textview = new TextView(this);
textview.setText(value);
setContentView(textview);}
}
I tryed with creating new instance of class Rezultati in function isci(View view) and calling function update
Rezultati r=new Rezultati();
r.update();
Unless nothing is in update function when i call r.update() it works, otherwise everytime stops working.
What am i doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请使用 GlobalVariablesApplication 将附加项放入其中,无论您在何处获得
附加项
,请参阅此链接 全局变量
Pls use the GlobalVariablesApplication to put the Extras in that and wherever u get the
Extras
see this link GlobalVariables