I'm doing this exercise with the fragments .. how do i see from the code i have developed .. i have my two classes fragment1 and fragment2, in the java / layout folder. There are then the two .xml files of the interfaces .. what is difficult now is to understand why this does not work properly .. what I have to get is: the screen must show two parts one with the script "This is the fragment 1" and on the other side "This is the fragment 2" ... but this is not visible I even attach the screens .. if you have time and patience, look up your news .. thanks and good day :) fragment1.java
package layout;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.test.testfragment.R;
/**
* A simple {@link Fragment} subclass.
*/
public class fragment1 extends Fragment {
public fragment1(){
}
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState){
return inflater.inflate(R.layout.fragment1,container,false);
}
}
fragment2.java
package layout;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.test.testfragment.R;
/**
* A simple {@link Fragment} subclass.
*/
public class fragment2 extends Fragment {
public fragment2(){
}
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState){
return inflater.inflate(R.layout.fragment2, container,false);
}
}
fragment1.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:ignore="HardcodedText">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Questo e' il fragment 1"
android:textSize="25sp"/>
</LinearLayout>
fragment2.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00FF00"
tools:ignore="HardcodedText">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Questo e' il fragment 2"
android:textSize="25sp"/>
</LinearLayout>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:baselineAligned="false"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context="com.example.test.testfragment.MainActivity">
<fragment
android:id="@+id/fragment1"
android:layout_width="0px"
android:name="layout.fragment1"
android:layout_height="match_parent"
android:layout_weight="1"
tools:layout="@layout/fragment1" />
<fragment
android:name="layout.fragment2"
android:id="@+id/fragment2"
android:layout_weight="1"
android:layout_width="0px"
android:layout_height="match_parent" />
</LinearLayout>