Android tabs with ActionBarSherlock and fragments using newInstance - android

I've just set up a project using tabs + actionbarsherlock + fragments, and want to make sure my approach is correct before moving on - mainly the use of my onTabSelected calling newInstance, this example is derived from CommonsWare's https://github.com/commonsguy/cw-omnibus/tree/master/ActionBar/TabFragmentDemo sample code.
My TabFragmentActivity:
public class TabFragmentActivity extends SherlockFragmentActivity
implements TabListener {
private static final String KEY_POSITION="position";
#Override
public void onCreate(Bundle state) {
super.onCreate(state);
ActionBar bar=getSupportActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
bar.setDisplayShowTitleEnabled(false);
bar.setDisplayShowHomeEnabled(false);
bar.addTab(bar.newTab().setText(R.string.tab1)
.setTabListener(this).setTag(0));
bar.addTab(bar.newTab().setText(R.string.tab2)
.setTabListener(this).setTag(1));
bar.addTab(bar.newTab().setText(R.string.tab3)
.setTabListener(this).setTag(2));
bar.addTab(bar.newTab().setText(R.string.tab4)
.setTabListener(this).setTag(3));
if (state != null) {
bar.setSelectedNavigationItem(state.getInt(KEY_POSITION));
}
}
#Override
public void onSaveInstanceState(Bundle state) {
state.putInt(KEY_POSITION,
getSupportActionBar().getSelectedNavigationIndex());
}
#Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
int i=((Integer)tab.getTag()).intValue();
if (i == 0){
ft.replace(android.R.id.content,
Tab1Fragment.newInstance(i));
}
else if (i == 1){
ft.replace(android.R.id.content,
Tab2Fragment.newInstance(i));
}
else if (i == 2){
ft.replace(android.R.id.content,
Tab3Fragment.newInstance(i));
}
else if (i == 3){
ft.replace(android.R.id.content,
Tab4Fragment.newInstance(i));
}
}
#Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
#Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
My Tab1Fragment:
public class Tab1Fragment extends SherlockFragment {
private static final String KEY_POSITION="position";
static Tab1Fragment newInstance(int position) {
Tab1Fragment frag=new Tab1Fragment();
Bundle args=new Bundle();
args.putInt(KEY_POSITION, position);
frag.setArguments(args);
return(frag);
}
#Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
View result=inflater.inflate(R.layout.tab1, container, false);
return(result);
}
}
Where my Tab1Fragment will eventually do a lot of AsyncTask heavy loading - is this ok as well?

Related

Fragment is not attaching to respective fragment

I am trying to attach ActionBar Tabs to respect fragment, But it is not working. I don't no where i am getting wrong.
Here is my FragmentActivity
public class MainActivity extends FragmentActivity implements TabListener {
String cPlusPlusFrag = "CPP", javaFrag = "Java";
CPlusPlusFragment cPlusPlusFragment;
JavaFragment javaFragment;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar mAction = getActionBar();
mAction.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
createTab(mAction, cPlusPlusFrag);
createTab(mAction, javaFrag);
}
public void createTab(ActionBar mActionBar, String tabName) {
Tab tab = mActionBar.newTab();
tab.setText(tabName);
tab.setTabListener(this);
mActionBar.addTab(tab);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
Toast.makeText(this, tab.getText() + "Re-Selected", Toast.LENGTH_LONG)
.show();
}
#Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
if (cPlusPlusFrag.equals(tab.getText())) {
if (cPlusPlusFragment == null) {
cPlusPlusFragment = new CPlusPlusFragment();
ft.add(android.R.id.content, cPlusPlusFragment);
}
} else if (javaFrag.equals(tab.getText())) {
if (javaFragment == null) {
javaFragment = new JavaFragment();
ft.add(android.R.id.content, javaFragment);
}
}
}
#Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
Toast.makeText(this, tab.getText() + " Un-Selected", Toast.LENGTH_LONG)
.show();
if (cPlusPlusFrag.equals(tab.getText().toString())) {
ft.detach(cPlusPlusFragment);
} else if (javaFrag.equals(tab.getText().toString())) {
ft.detach(javaFragment);
}
}
}
Java Fragment code.
public class JavaFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View viewToInflate = inflater.inflate(R.layout.java_frag_layout,
container);
return viewToInflate;
};
}
C++ Fragment code.
public class CPlusPlusFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View viewToInflate = inflater.inflate(R.layout.cplusplus_frag_layout,
container);
return viewToInflate;
}
}
The Problem is in
methods: onTabSelected, onTabUnSelected
and variables: cPlusPlusFragment and javaFrag (You did not Declared/Created them anywhere)
*Solution*
// The following variables are at Class level (data members)
String cPlusPlusFragment = "C++";
String javaFrag = "Java"
// Pass them in the method createTab accordingly
createTab(mActionBar, cPlusPlusFragment);
createTab(mActionBar, javaFrag);
// Modify you onTabSelected and onTabUnselected methods as follows:
#Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
if (cPlusPlusFrag.equals(tab.getText().toString)) {
if (cPlusPlusFragment == null) {
cPlusPlusFragment = new CPlusPlusFragment();
// No need to Create custom FragmentTransaction, use
// one that is passed in the argument
ft.add(android.R.id.content, cPlusPlusFragment);
} else {
ft.attach(cPlusPlusFragment);
}
} else if (javaFrag.equals(tab.getText().toString)) {
if (javaFragment == null) {
javaFragment = new JavaFragment();
ft.add(android.R.id.content, javaFragment);
} else {
ft.attach(javaFragment);
}
}
}
#Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
Toast.makeText(this, tab.getText() + " Un-Selected", Toast.LENGTH_LONG)
.show();
if (cPlusPlusFrag.equals(tab.getText().toString)) {
ft.detach(cPlusPlusFragment);
} else if (javaFrag.equals(tab.getText().toString)) {
ft.detach(javaFragment);
}
}
I am 100 % sure that this will solve your problem :)
I see nothing wrong in you code at first sight apart from the fact that you are not commiting your fragment changes.
EveryTime you call to getFragmentManager().beginTransaction(). you have to call .commit() at the end of the line like this:
getFragmentManager().beginTransaction().replace(R.id.main_layout, javaFragment).commit();
Hope it helps :)

Play with fragments in onTabSelected

Dears,
I searched for this issue for more than a day but with no luck.
I implement exactly the code posted here:
Adding Navigation Tabs
My code for onTabSelected look like:
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// Check if the fragment is already initialized
if (mFragment == null) {
// If not, instantiate and add it to the activity
mFragment = Fragment.instantiate(mActivity, mClass.getName());
ft.add(R.id.alert_fragment_container, mFragment, mTag);
} else {
// If it exists, simply attach it in order to show it
ft.attach(mFragment);
}
// prepare adapter for ExpandableListView
Log.i("After Adapter Created", "Passed");
final ExpandableListAdapter expListAdapter = new AlertsAdapter(
mActivity, myAlerts, violations);
Log.i("After Adapter Initialized", "Passed");
((MyCustomFragment)mFragment).violations.setAdapter(expListAdapter);
}
The code is working fine till last line, where I need to set the adapter for public static list initialized in MyCustomFragment in onCreateView, here my code for fragment:
public class MyCustomFragment extends Fragment {
public MyCustomFragment() {
}
public static ExpandableListView violations;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_alerts_poi, container, false);
violations = (ExpandableListView) rootView.findViewById(R.id.POIAlertList);
Log.i("onCreateView POI", "Called");
return rootView;
}
}
It give Null pointer error. With my debugging logs, I notice that this log Log.i("onCreateView POI", "Called"); appears after this Log.i("After Adapter Initialized", "Passed");. This means that I'm trying to set the adapter for a fragment isn't initialized yet.
This is the exact problem I'm face, I need to fed the ExpandableListView with data based on Tab selection in onTabSelected.
What I'm doing wrong? What is the best solution?
Regards,
It seems that you need a ViewPager, I just implemented a navigation tabs few days ago, here is my code, it navigates between 4 fragments:
public class MainActivity extends FragmentActivity implements ActionBar.TabListener{
private ActionBar actionBar;
private ViewPager mViewPager;
private AppSectionsPagerAdapter mAppSectionsPagerAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());
actionBar=getActionBar();
actionBar.setHomeButtonEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mAppSectionsPagerAdapter);
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
#Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
});
actionBar.addTab(actionBar.newTab().setIcon(R.drawable.icon1).setTabListener(this));
actionBar.addTab(actionBar.newTab().setIcon(R.drawable.icon2).setTabListener(this));
actionBar.addTab(actionBar.newTab().setIcon(R.drawable.icon3).setTabListener(this));
actionBar.addTab(actionBar.newTab().setIcon(R.drawable.icon4).setTabListener(this));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
getMenuInflater().inflate(R.menu.action_menu, menu);
return true;
}
#Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
#Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
mViewPager.setCurrentItem(tab.getPosition());
}
#Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
And here is the adapter:
public class AppSectionsPagerAdapter extends FragmentPagerAdapter {
public AppSectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int i) {
switch (i) {
case 0:
return new Fragment1();
case 1:
return new Fragment2();
case 2:
return new Fragment3();
case 3:
return new Fragment4();
}
return null;
}
#Override
public int getCount() {
return 4;
}
}
Have a look # this Tablayout.onTabselected for latest API updates. ActionBar.TabListener is a old implementation.

OnDetach/onAttach fragment recreate fragment activity

I want to detach/attach my fragments, but how to set, that fragment not recreate, after I attach.
In fragment I have WebView; when I select and unselect tabs, webview load startpage.
There is my code:
public class MainActivity extends Activity implements OnClickListener, OnMenuItemClickListener {
ActionBar bar;
View v;
public static TextView tilt;
LayoutInflater inflater;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
onAddTab();
View v=getLayoutInflater().inflate(R.layout.action_bar, null);
ImageButton im = (ImageButton)v.findViewById(R.id.tab_toggle);
im.setOnClickListener(this);
getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.shape_layout));
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getActionBar().setCustomView(v);
onToggleTabs();
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.tab_toggle:
onAddTab();
break;
}
}
public void onAddTab() {
final ActionBar bar = getActionBar();
View v=getLayoutInflater().inflate(R.layout.layout_tab, null);
tilt = (TextView)v.findViewById(R.id.tit_le);
ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.CENTER;
v.setLayoutParams(lp);
closetab = (ImageButton)v.findViewById(R.id.close);
closetab.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
onRemoveTab();
}
});
bar.addTab(bar.newTab()
.setCustomView(v)
.setTabListener(new TabListener<Web>(this, "Tag A", Web.class)));
}
public void onRemoveTab() {
final ActionBar bar = getActionBar();
Tab tab = bar.getSelectedTab();
bar.removeTab(tab);
}
public void onToggleTabs() {
final ActionBar bar = getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
}
public void onRemoveAllTabs(View v) {
getActionBar().removeAllTabs();
}
public static class TabListener<T extends Fragment> implements ActionBar.TabListener{
private final Activity myActivity;
private final String myTag;
private final Class<T> myClass;
public TabListener(Activity activity, String tag, Class<T> cls) {
myActivity = activity;
myTag = tag;
myClass = cls;
}
#Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
Fragment myFragment = myActivity.getFragmentManager().findFragmentByTag(myTag);
// Check if the fragment is already initialized
if (myFragment == null) {
// If not, instantiate and add it to the activity
myFragment = Fragment.instantiate(myActivity, myClass.getName());
ft.add(R.id.fragment0, myFragment, myTag);
} else {
// If it exists, simply attach it in order to show it
ft.attach(myFragment);
}
}
#Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
Fragment myFragment = myActivity.getFragmentManager().findFragmentByTag(myTag);
if (myFragment != null) {
// Detach the fragment, because another one is being attached
ft.detach(myFragment);
}
}
#Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
}
There is Fragment:
public class Web extends Fragment implements OnLongClickListener, OnClickListener{
#Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
c=this.getActivity();
v = inflater.inflate(R.layout.activity_main, container, false);
return v;
}
#SuppressWarnings("deprecation")
#Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
setRetainInstance(true);
wv = (WebView)v.findViewById(R.id.wv);
wv.setWebChromeClient(new WebChromeClient(){
#Override
public void onProgressChanged(WebView view, int progress) {
// TODO Auto-generated method stub
super.onProgressChanged(view, progress);
if(progress < 100 && pr.getVisibility() == ProgressBar.GONE){
pr.setVisibility(ProgressBar.VISIBLE);
}
pr.setProgress(progress);
if(progress == 100) {
pr.setVisibility(ProgressBar.GONE);
}
}
});
wv.setWebViewClient(new MyWebViewClient());
wv.loadUrl("http://www.google.com");
wv.setOnLongClickListener(this);}
Try setRetainInstance(boolean)
Also check this posts:
Android fragments setRetainInstance(true) not works (Android support library)
Fragment setRetainInstance not works (Android support lib)
Understanding Fragment's setRetainInstance(boolean)

Tab and fragments no support intents

Hi I have a problem with tab+fragment, here frist I have the class which will create the tab:
public class TestSwipeABActivity extends FragmentActivity {
FragmentTransaction transaction;
static ViewPager mViewPager;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Fragment tabOneFragment = new TabOne();
Fragment tabTwoFragment = new TabTwo();
PagerAdapter mPagerAdapter = new PagerAdapter(getSupportFragmentManager());
mPagerAdapter.addFragment(tabOneFragment);
mPagerAdapter.addFragment(tabTwoFragment);
//transaction = getSupportFragmentManager().beginTransaction();
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mPagerAdapter);
mViewPager.setOffscreenPageLimit(2);
mViewPager.setCurrentItem(0);
mViewPager.setOnPageChangeListener(
new ViewPager.SimpleOnPageChangeListener() {
#Override
public void onPageSelected(int position) {
// When swiping between pages, select the
// corresponding tab.
getActionBar().setSelectedNavigationItem(position);
}
});
ActionBar ab = getActionBar();
ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Tab tab1 = ab.newTab().setText("Tab One").setTabListener(new TabListener<TabOne>(
this, "tabone", TabOne.class));
Tab tab2 = ab.newTab().setText("Tab Two").setTabListener(new TabListener<TabTwo>(
this, "tabtwo", TabTwo.class));
ab.addTab(tab1);
ab.addTab(tab2);
}
public static class TabListener<T extends Fragment> implements ActionBar.TabListener {
private Fragment mFragment;
private final Activity mActivity;
private final String mTag;
private final Class<T> mClass;
/** Constructor used each time a new tab is created.
* #param activity The host Activity, used to instantiate the fragment
* #param tag The identifier tag for the fragment
* #param clz The fragment's Class, used to instantiate the fragment
*/
public TabListener(Activity activity, String tag, Class<T> clz) {
mActivity = activity;
mTag = tag;
mClass = clz;
}
/* The following are each of the ActionBar.TabListener callbacks */
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// Check if the fragment is already initialized
if (mFragment == null) {
// If not, instantiate and add it to the activity
mFragment = Fragment.instantiate(mActivity, mClass.getName());
ft.add(android.R.id.content, mFragment, mTag);
} else {
// If it exists, simply attach it in order to show it
ft.attach(mFragment);
}
}
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
if (mFragment != null) {
// Detach the fragment, because another one is being attached
ft.detach(mFragment);
}
}
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// User selected the already selected tab. Usually do nothing.
}
public void onTabReselected(Tab arg0,
android.app.FragmentTransaction arg1)
{
// TODO Auto-generated method stub
}
public void onTabSelected(Tab arg0, android.app.FragmentTransaction arg1)
{
// TODO Auto-generated method stub
mViewPager.setCurrentItem(arg0.getPosition());
}
public void onTabUnselected(Tab arg0,
android.app.FragmentTransaction arg1)
{
// TODO Auto-generated method stub
}
}
public class PagerAdapter extends FragmentPagerAdapter {
private final ArrayList<Fragment> mFragments = new ArrayList<Fragment>();
public PagerAdapter(FragmentManager manager) {
super(manager);
}
public void addFragment(Fragment fragment) {
mFragments.add(fragment);
notifyDataSetChanged();
}
#Override
public int getCount() {
return mFragments.size();
}
#Override
public Fragment getItem(int position) {
return mFragments.get(position);
}
}
}
And then here is the fragment for each tab, for example the two one:
public class TabTwo extends Fragment
{
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.tabtwo, container, false);
Button Activity1= (Button) view.findViewById(R.id.button1);
Activity1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent().setClass(this,ABActivity.class);
startActivity(intent);
}
});
return view;
}
}
The error was: The method setClass(Context, Class<?>) in the type Intent is not applicable for the arguments (new View.OnClickListener(){},
Class<ABActivity>)
I try out changing the context to TabTwo.this, tabtwo.getcontext.this, but nothing, eclipse says to change .setclassName but doesnt work.
If you could help... THANKS!!!
Try this
Intent intent = new Intent(getActivity(),ABActivity.class);
startActivity(intent );
HI I just have a solution:
public void onClick(View view) {
Activity activity = getActivity();
Intent intent = new Intent().setClass(activity, ABActivity.class);
startActivity(intent);
}
Explanation: "Another difference is that a Fragment is not a subclass of Context. This means that a Fragment can not be launched as a component inside your app and therefore always has to live inside of an Activity. This also means that whenever you need a Context inside of a Fragment, you need to get access to the parent Activity. You can do this by using the getActivity() method as we have done in the Fragment button's OnClickListener callback. You need to watch out because getActivity() can return null depending on where the Fragment is in the Activity's lifecycle. So, you should also include a check to see if the Activity is null before you use it."
FROM: http://neilgoodman.net/2012/01/29/working-with-fragments-on-android-part-1/

Fragment not showing at Activity start up

I coded a UI using Action Bar Sherlock.
I accomplish to swap fragments (and showing its own data), but when my Activity is created, nothing appears.
Here my code:
public class TabsActivity extends SherlockFragmentActivity{
public static DetailedClinica detailedClinica=null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SimpleClinica clinica = (SimpleClinica) getIntent().getParcelableExtra("clinica");
try {
detailedClinica = getDetailedClinica(clinica.getIdClinica().toString());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab newTab0 = getSupportActionBar().newTab();
newTab0.setText("Info");
//fillFirstTab(clinica,newTab0);
ActionBar.Tab newTab1 = getSupportActionBar().newTab();
newTab1.setText("Dettagli");
getSupportActionBar().addTab(newTab0);
getSupportActionBar().addTab(newTab1);
newTab0.setTabListener(new TabListener());
newTab1.setTabListener(new TabListener());
}
public class TabListener implements ActionBar.TabListener {
public void onTabSelected(Tab tab, FragmentTransaction ft) {
if (tab.getPosition() == 0){
FragmentClinica fragmentClinica = new FragmentClinica();
ft.replace(android.R.id.content, fragmentClinica);
}else{
FragmentDetailed fragmentDetailed = new FragmentDetailed();
ft.replace(android.R.id.content, fragmentDetailed);
}
}
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
FragmentClinica arg0 = new FragmentClinica();
ft.detach(arg0);
}
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
where FragmentClinica is:
public class FragmentClinica extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup group, Bundle saved){
return inflater.inflate(R.layout.tab1, group, false);
}
#Override
public void onActivityCreated (Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
TextView textView = (TextView) getActivity().findViewById(R.id.textView1);
textView.setText("Ciao");
}
}
Suggestions??
Thanks in advance
When you do a FragmentTransaction, you have to commit the change
...
ft.commit();
I don't see anywhere that you have set the contents of the tabs...
perhaps you need to un-comment the following line of code?
//fillFirstTab(clinica,newTab0);

Categories

Resources