I am testing basic Fragements stuff, so i created 4 classes , 1 MainActivity, 1 FragmentActivity and 2 Fragments, the idea is that we invoke the FragmentActivity via a button from the MainActivity, which should show then Fragment1 and Fragment2 , as Fragment1 having 30 % of the screen with orrange background and Fragment 2 the 70 % with background blue.There is no error , just when i click the button in the MainActivity , it goes to the FragmentActivity , but shows white screen with only the textview , but when i go into the .xml file on the FragmentActivity it shows the Orange-Blue screen ?
here is the MainActivity part
buttonFrag2.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,StaticFragment.class);
startActivity(intent);
}
});
then the StaticFragment Class
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
public class StaticFragment extends FragmentActivity {
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
}
}
and the static_fragment.xml , which as said is shown correctly in the Graphical Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false"
>
<fragment
android:name="com.example.fragment.ListFrag"
android:id="@+id/listFrag"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight=".3"
tools:layout="@layout/list_frag" />
<fragment
android:name="com.example.fragment.DetailFrag"
android:id="@+id/detailFrag"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight=".7"
tools:layout="@layout/detail_frag" />
</LinearLayout>
also as an example one of the Fragment classes (they are identical)
package com.example.fragment;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class ListFrag extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
return inflater.inflate(R.layout.list_frag, container, false);
}
}