Professional Documents
Culture Documents
XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="@+id/fragment_content_1"
android:name="com.example.fragmentexample.Fragment_1"
android:layout_width="0dip"
android:layout_weight="0.50"
android:layout_height="fill_parent" >
</fragment>
<fragment
android:id="@+id/fragment_content_2"
android:name="com.example.fragmentexample.Fragment_2"
android:layout_width="0dip"
android:layout_weight="0.50"
android:layout_height="fill_parent" >
</LinearLayout>
Fragment_1.Java
public class Fragment_1 extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
btnSayHi_Fragment.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
FragmentManager fm = getFragmentManager();
Fragment_2 f2 = (Fragment_2)
fm.findFragmentById(R.id.fragment_content_2);
if(activity != null)
{
Toast.makeText(activity, "Say&ing Hi in Progress...",
Toast.LENGTH_LONG).show();
}
}
});
return view;
Fragment_2.Java
public class Fragment_2 extends Fragment{
View view;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub