changed method of tab use

This commit is contained in:
Tom Hennen 2015-09-05 17:17:05 -04:00
parent 1d38db32d5
commit 9fe8750ecb
5 changed files with 82 additions and 41 deletions

View File

@ -12,6 +12,7 @@ dependencies {
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:gridlayout-v7:22.2.1'
compile 'com.android.support:cardview-v7:22.2.1'
compile 'com.android.support:design:22.2.1'
compile 'org.apache.commons:commons-lang3:3.3.2'
compile('org.shredzone.flattr4j:flattr4j-core:2.12') {
exclude group: 'org.json', module: 'json'

View File

@ -0,0 +1,59 @@
package de.danoeh.antennapod.adapter;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.fragment.AllEpisodesFragment;
import de.danoeh.antennapod.fragment.NewEpisodesFragment;
public class EpisodesPagerAdapter extends FragmentPagerAdapter {
private final Context context;
private String tabTags[] = new String[] {AllEpisodesFragment.TAG, NewEpisodesFragment.TAG};
private String tabTitles[] = new String[tabTags.length];
public EpisodesPagerAdapter(FragmentManager fm, Context context) {
super(fm);
this.context = context;
tabTitles = new String[tabTags.length];
for (int i = 0; i < tabTags.length; i++) {
String title = null;
switch (tabTags[i]) {
case AllEpisodesFragment.TAG:
title = context.getResources().getString(R.string.all_episodes_label);
break;
case NewEpisodesFragment.TAG:
title = context.getResources().getString(R.string.new_episodes_label);
break;
}
tabTitles[i] = title;
}
}
@Override
public Fragment getItem(int position) {
String tag = tabTags[position];
switch (tag) {
case AllEpisodesFragment.TAG:
return new AllEpisodesFragment();
case NewEpisodesFragment.TAG:
return new NewEpisodesFragment();
}
return null;
}
@Override
public int getCount() {
return tabTags.length;
}
@Override
public CharSequence getPageTitle(int position) {
return tabTitles[position];
}
}

View File

@ -1,20 +1,21 @@
package de.danoeh.antennapod.fragment;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTabHost;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.adapter.EpisodesPagerAdapter;
public class EpisodesFragment extends Fragment {
public static final String TAG = "EpisodesFragment";
private FragmentTabHost mTabHost;
//Mandatory Constructor
public EpisodesFragment() {
}
@ -22,26 +23,18 @@ public class EpisodesFragment extends Fragment {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.episodes_fragment, container, false);
ViewPager pager = (ViewPager)rootView.findViewById(R.id.viewpager);
pager.setAdapter(new EpisodesPagerAdapter(getChildFragmentManager(), getActivity()));
mTabHost = (FragmentTabHost) rootView.findViewById(android.R.id.tabhost);
mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);
mTabHost.addTab(mTabHost.newTabSpec(NewEpisodesFragment.TAG).setIndicator(
getResources().getString(R.string.new_episodes_label)),
NewEpisodesFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec(AllEpisodesFragment.TAG).setIndicator(
getResources().getString(R.string.all_episodes_label)),
AllEpisodesFragment.class, null);
// Give the TabLayout the ViewPager
TabLayout tabLayout = (TabLayout) rootView.findViewById(R.id.sliding_tabs);
tabLayout.setupWithViewPager(pager);
return rootView;
}

View File

@ -1,33 +1,21 @@
<android.support.v4.app.FragmentTabHost
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget
android:id="@android:id/tabs"
android:orientation="horizontal"
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"/>
app:tabMode="scrollable" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<FrameLayout
android:id="@+id/realtabcontent"
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
android:layout_height="0px"
android:layout_weight="1"
android:background="@android:color/white" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
</LinearLayout>

View File

@ -36,7 +36,7 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:22.2.1'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:support-v4:22.2.1'
compile 'com.android.support:design:22.2.1'
compile 'org.apache.commons:commons-lang3:3.3.2'
compile ('org.shredzone.flattr4j:flattr4j-core:2.12') {
exclude group: 'org.json', module: 'json'