我在android开发教程中有3个Tabs
现在我想要做的很简单,我在每个页面上使用Fragments.我想在每个页面上显示rss feed中的不同内容.
问题是,当我转到下一个选项卡时,它运行前一个Fragment的AsyncTask(在onCreateView中).
因此,从第1页开始,它可以很好地加载内容.然后当你去第2页再次运行第1页片段的onCreateView时.显然会给出NullException.关键是它不应该在第2页运行Page 1的AsyncTask.
我不认为有任何示例代码需要告诉我你需要看哪个部分.然后我会编辑我的问题.
ListFragment中的AsyncTask:
public class MyAsyncTask extends AsyncTask<List<String>, Void, List<String>>
{
// List of messages of the rss feed
private List<Message> messages;
private volatile boolean running = true;
@SuppressWarnings("unused")
private WeakReference<NieuwsSectionFragment> fragmentWeakRef;
private MyAsyncTask(NieuwsSectionFragment fragment)
{
this.fragmentWeakRef = new WeakReference<NieuwsSectionFragment>(fragment);
}
@Override
protected void onPreExecute()
{
super.onPreExecute();
mProgress.show();
// progress.setVisibility(View.VISIBLE); //<< set here
}
@Override
protected void onCancelled()
{
Log.w("onCancelled", "now cancelled");
running = false;
}
@Override
protected List<String> doInBackground(List<String>... urls)
{
FeedParser …Run Code Online (Sandbox Code Playgroud) android android-asynctask android-fragments android-viewpager android-fragmentactivity
在此链接中:如何以编程方式应用样式?
凯文格兰特对这个问题进行了解释我的问题与他的代码是上下文部分.确切地说:
ctv = new CustomView(context, R.attr.tabStyleAttr);
Run Code Online (Sandbox Code Playgroud)
在这段代码中它说:上下文无法解析为变量
我想将特定样式应用于选项卡,这就是设置主题对我不起作用的原因.我当然也欢迎任何替代我的问题.
我尝试更改操作栏选项卡的背景颜色,指示器颜色和文本颜色.
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
{
CustomView ctv;
ctv = new CustomView(this, R.attr.tabStyleAttr);
tab.setCustomView(ctv);
mViewPager.setCurrentItem(tab.getPosition());
}
Run Code Online (Sandbox Code Playgroud)
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Ab" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/abStyle</item>
<item name="@attr/actionBarTabStyle">@style/tabStyle</item>
<item name="android:actionBarTabTextStyle">@style/tabTextColor</item>
</style>
<style name="abStyle" parent="@android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:background">@drawable/ab_solid_style</item>
<item name="android:backgroundStacked">@drawable/ab_stacked_solid_style</item>
<item name="android:backgroundSplit">@drawable/ab_bottom_solid_style</item>
<item name="android:height">100dp</item>
</style>
<style name="tabStyle" parent="@android:style/Widget.Holo.Light.ActionBar.TabView">
<item name="android:background">@drawable/tab_indicator_ab_style</item>
</style>
<style name="tabTextColor" parent="@android:style/Widget.Holo.Light.ActionBar.TabText">
<item name="android:textColor">@android:color/white</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
MainActivity.java(onCreate)
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create the …Run Code Online (Sandbox Code Playgroud) android android-viewpager android-tabs android-actionbar-compat
是否可以删除objective-C/xCode中的html div?所以例如html看起来像这样:
<html>
<div id="menu"> the menu code </div>
<p> lorem ipsum text </p>
</html>
Run Code Online (Sandbox Code Playgroud)
因此,如果我可以删除此菜单,则仅显示文本内容.这就是我想要做的.