2017-11-15 10 views
0

私は断片とこの練習をしています..どのように私が開発したコードから参照してください..私は私の2つのクラスfragment1とfragment2、java /レイアウトフォルダ。次に、インターフェイスの2つの.xmlファイルがあります。なぜこれが適切に動作しないのか理解することは難しいです。私が取得しなければならないのは、画面にスクリプトの2つの部分が表示されている必要があります。 "これはフラグメント1 "と反対側に"これは断片2です... "しかし、これは表示されません私はさらに画面を添付..あなたは時間と忍耐があれば、あなたのニュースを見て..ありがとう、良い日:) 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

+0

いくつかのアプリから電話を掃除した後、私はGradle ProjectsとinstallDebugを使ってインストールしました。皆さん、ありがとうございました !! – Serra

答えて

0

エラーコードのためではない、それが正常にビルドされ、unistallingしてみてくださいデバイスからのアプリとクリーンbuプロジェクトを再実行してください。それはうまくいくはずです。

+0

あなたの答えをありがとうYogesh ..申し訳ありませんが、あなたが私に提案することは、新しいプロジェクトを作ることです。これを削除するには大丈夫ですが、アプリケーションを実行している私のデバイスからは、 – Serra

+0

https:// stackoverflowも表示されません。 com/questions/37015030/session-app-error-installing-apkこれはurの問題を解決する可能性があります – Yogesh

0

adbでapkをインストールしてみてください。失敗した場合はエラーメッセージが表示されます。

adb install my.apk 
関連する問題