0

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>

activity_main (Design)

Error

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Serra
  • 1
  • 2
  • After cleaning the phone from a few apps, I managed to install through Gradle Projects and using installDebug .. now the app looks like I wanted ! Thank you all !! – Serra Nov 15 '17 at 13:30

2 Answers2

0

The error is not for the code, it is built successfully, try unistalling the app from the device and clean build the project then try running again. That should work.

Yogesh
  • 418
  • 1
  • 4
  • 12
  • Thanks for your answer Yogesh .. sorry but what you suggest me to do is make a new project .. well it's okay to delete this, but from my device where i run the app is not even displayed – Serra Nov 15 '17 at 10:54
  • https://stackoverflow.com/questions/37015030/session-app-error-installing-apk this may address ur problem – Yogesh Nov 15 '17 at 11:27
0

try installing the apk with adb , if it fails you will get an error message ,then you can work on that.

adb install my.apk
himel
  • 500
  • 5
  • 14