Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I use "tab bar" to separate main screen(Fragment1,2,3). In one of my main screen(MainActivity), I try to make more page. So I use Inent to link from Fragment 1_1 to Fragment1_2. I doubt it about extends Fragment that why I can't use any method on this class.

Java
public class Fragment1_1 extends Fragment {
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		
		 return inflater.inflate(R.layout.fragment1_1, null);
	}
	

	public void btnNext(View view){
		Intent nextScreen = new Intent(getApplicationContext(),Fragment1_2.class);
		 startActivity(nextScreen);
	}
}


getApplicationContext() error. Somebody know How to OnClick like this page? pls help and thanks a lot.

when I use "extends fragment" many stuff dun work.
Posted
Updated 20-Jul-14 21:09pm
v4

1 solution

http://developer.android.com/guide/components/fragments.html#Transactions[^]

You should use the FragmentTransaction.

have fun!
 
Share this answer
 
Comments
Eerven 21-Jul-14 3:52am    
thanks, but it's kind like confuse there haha..
TorstenH. 21-Jul-14 4:06am    
It's THE tutorial - and actually a pretty good one.
Eerven 21-Jul-14 4:57am    
public class Fragment1_1 extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment1_1,null);
Button btnNext = (Button)rootView.findViewById(R.id.btnext);

btnNext.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
nextscreen();
}
});

return rootView;
//return inflater.inflate(R.layout.fragment1_1, null);
}

public void nextscreen(){
Intent nextScreen = new Intent(getActivity(), Fragment1_2.class);
startActivity(nextScreen);
}
}

I got this solution back but still not work ,Do Frament1_2 have to "extends Fragment" too?
TorstenH. 21-Jul-14 5:20am    
To create a fragment, you must create a subclass of Fragment (or an existing subclass of it)

if a class "Fragment2" does not inherit from "Fragment", then it's just a pojo and nothing more.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900