Well, I'm starting to understand Android Fragments, but this is still confusing for me. I need a little help. As they say, Android fragments are supported from API level 11, but you can download the “support.v4” library package for the lower-level API. First I create a new project to try fragments at API level 15. Then I did the same with API level 8 and it doesn’t work ... I imported an external jar and it sees all the necessary imports as it should ... What seems to be the problem here?
Here is my main class:
import android.support.v4.app.FragmentActivity; import android.os.Bundle; public class Fragment2Activity extends FragmentActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
My main XML format is:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <fragment android:name="com.frag.Fragment2.frag" android:id="@+id/frag" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout>
My fragment class:
import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class frag extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
And my XML fragment:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="match_parent" android:text="THIS IS FRAGMENT" android:background="@drawable/ic_launcher" /> </LinearLayout>
Fixed
source share