【发布时间】:2014-01-08 14:22:29
【问题描述】:
基本上我的代码与here 描述的代码完全相同:
在每个片段中,我都有不同的异步任务,它只是从网站获取数据。 它看起来像这样:
TextView text;
String content;
View today;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
today = inflater.inflate(R.layout.today, container, false);
text = (TextView) today.findViewById(R.id.textView);
// ((TextView) today.findViewById(R.id.textView)).setText("Today");
new RetriveSiteData().execute("http://menza.lupajz.eu/?den=dnes");
content = (String) text.getText();
return today;
}
我想知道如果 TabPagerAdapter 类(在网站上),是否总是获取数据,同时在片段中滑动 这个方法是否以相同的方式实现
@Override
public Fragment getItem(int i) {
switch (i) {
case 0:
//Fragement for Android Tab
return new Android();
case 1:
//Fragment for Ios Tab
return new Ios();
case 2:
//Fragment for Windows Tab
return new Windows();
}
return null;
}
如果始终获取数据并且始终执行异步任务,我该如何防止这种情况发生?也许为每个片段添加一些 onResume() 方法?
【问题讨论】:
-
把你的逻辑(异步任务)放在片段的
onStart()方法中。看看有没有变化。确保覆盖这些方法。
标签: android android-fragments android-asynctask