Results 1 to 3 of 3
  1. #1
    negar is offline Member
    Join Date
    Apr 2013
    Posts
    16
    Rep Power
    0

    Default where is the problem with my fragments?

    I'm new to Android and want to use fragments for first time...but the main.xml doesn't connect to fragments...this is the code:
    Java Code:
    <?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" 
        android:background="#FFFE00" >
        <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/f2"
            android:textColor="#000000"
            android:textSize="25sp"
            />
    
    </LinearLayout>
    .............................................
    <?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" 
        android:background="#00FF00"
        >
        <TextView android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:textColor="#000000"
             android:text="@string/f1"
            android:textSize="25sp"
            />
    
    </LinearLayout>
    ................................................an d the main.xml is:
    Java Code:
    <?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="horizontal" >
    
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
        <fragment android:name="com.android.frag.fragment1" 
            android:id="@+id/fragment1"
            android:layout_weight="1"
            android:layout_width="0px"
            android:layout_height="match_parent"
            />
     <fragment  android:name="com.android.frag.fragment2"
         android:id="@+id/fragment2"
            android:layout_weight="1"
            android:layout_width="0px"
            android:layout_height="match_parent"
            />
     
    </LinearLayout>
    and the fragment.java:
    Java Code:
    package com.android.frag;
    
    import android.app.Fragment;
    import android.os.Bundle;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    
    public class fragment1 extends Fragment{
    	@Override
      public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
    	  return inflater.inflate(R.layout.fragment1,container,false);
      }
    }


    please help me
    Last edited by negar; 08-21-2013 at 08:14 PM.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,083
    Rep Power
    4

    Default Re: where is the problem with my fragments?

    Please go through the Guide For New Members and BB Code List - Java Programming Forum - Learn Java Programming and learn how to post code on this forum.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    negar is offline Member
    Join Date
    Apr 2013
    Posts
    16
    Rep Power
    0

    Default Re: where is the problem with my fragments?

    hi all
    I finally figured it out.......
    and i tell the solution of problem for ones that will have the same trouble:
    the error was with the TextView in main.xml and as soon as I omitted it ,it worked.......
    Last edited by negar; 08-24-2013 at 05:26 PM.

Similar Threads

  1. Replies: 0
    Last Post: 11-07-2012, 12:44 PM
  2. Replies: 0
    Last Post: 12-13-2011, 07:38 PM
  3. Small problem with problem with Java, C++ parse program.
    By dragstang86 in forum New To Java
    Replies: 4
    Last Post: 10-30-2011, 03:43 AM
  4. Replies: 9
    Last Post: 09-21-2010, 04:15 PM
  5. Replies: 1
    Last Post: 08-20-2010, 11:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •