0

I'm new to android ecosystem, please help me this app is for my college project. I had created swiping tabs with 5 tabs using 5 fragments, and everything ( swiping back and forth) is working well. In my first tab ( first fragment) I have buttons which when clicked goes to other fragment ( this fragment is not among the 5 fragments used for tabs) i tried to use ft.replace() to perform this, but unfortunately right now when the button is clicked i'm directed to ' blank page' which is not my intended fragment - in fact this page is not my codes at all. below is the code of the Tab1 in which i'm trying to launch a new fragment. Please advice me where is the problem in my code.

import android.app.Activity;
import com.example.hfacs.R;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.view.View.OnClickListener;


public class Unsafe extends Fragment  {
@Override
 public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.unsafe, container, false);
    return v;
}

public void onActivityCreated(Bundle savedInstanceState){
    super.onActivityCreated(savedInstanceState);
    final Button button1 = (Button) getActivity().findViewById(R.id.u1);
    button1.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
        final android.support.v4.app.FragmentTransaction ft =        
        getFragmentManager().beginTransaction();
            ft.replace(R.id.pager, new Unsafe1());
            ft.commit();
        }
    });

   }



 }

This this my page adapter code for tabs

import com.example.hfacs.Unsafe;
import com.example.hfacs.Precondition;
import com.example.hfacs.Supervision;
import com.example.hfacs.Organization;
import com.example.hfacs.Summary;
import com.example.hfacs.Unsafe1;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

public class TabsPageAdapter extends FragmentPagerAdapter {

public TabsPageAdapter(FragmentManager fm) {
    super(fm);
}


@Override
public Fragment getItem(int index){
switch (index){
    case 0:
        return new Unsafe();
    case 1:
        return new Precondition();
    case 2:
        return new Supervision();
    case 3:
        return new Organization();
    case 4:
        return new Summary();



}
return null;
}
@Override
public int getCount() {
    return 5;
}}
Alexis
  • 73
  • 1
  • 2
  • 7
  • Check this out http://stackoverflow.com/questions/20366804/unable-to-replace-navigate-fragments/20366957#20366957. – AndroidHacker Dec 04 '13 at 11:01
  • Check this out http://stackoverflow.com/questions/20366804/unable-to-replace-navigate-fragments/20366957#20366957. Let me know if you have any other concern – AndroidHacker Dec 04 '13 at 11:02
  • @AndroidHacker Thank you for the quick reply. I read the thread i find it very complex may be i'm beginner, can you please share easier method to implement this please. – Alexis Dec 04 '13 at 11:18

0 Answers0