简体   繁体   English

从另一个活动更新活动

[英]Updating Activity from another Activity

I have SettingsActivity that extends PreferenceActivity and in setting I can specify how many EditTexts my MainActivity needs to show on screen. 我有一个扩展PreferenceActivity的SettingsActivity,在设置中,我可以指定我的MainActivity需要在屏幕上显示多少个EditTexts I am using global variable from helper class to achieve this. 我正在使用helper类的全局变量来实现这一点。 My SettingsActivity changes the value of global variable and my MainActivity reads this value and add as many EditTexts as needed. 我的SettingsActivity更改了全局变量的值,我的MainActivity读取此值并根据需要添加尽可能多的EditTexts。

But there is one problem, my MainActivity draws new EditTexts only after it has been minimized and then maximized, because this method that adds EditTexts is in onCreate method. 但是有一个问题,我的MainActivity只有在最小化然后最大化之后才会绘制新的EditTexts ,因为添加EditTexts这个方法是在onCreate方法中。 I tried to acces my public void addEditTexts(int amount) method (which is in MainActivity) from SettingsActivity without success. 我试图从SettingsActivity访问我的public void addEditTexts(int amount)方法(在MainActivity中),但没有成功。 Is there any other method to do this? 有没有其他方法可以做到这一点?

You should put your method that draws the EditTexts in the onResume() ; 你应该把你的方法绘制在onResume()中绘制EditTexts;

@Override
protected void onResume() {
    super.onResume();

    // Your method here
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM