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;
}}