3

I am creating tabBar in following way:

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;

public class FragmentTabs extends FragmentActivity {
private FragmentTabHost mTabHost;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.tabbar_layout);

    mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
    mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);

    mTabHost.addTab(mTabHost.newTabSpec("About Us").setIndicator("About Us"), FragmentAboutUsScreen.class, null);
    mTabHost.addTab(mTabHost.newTabSpec("Feedback").setIndicator("Feedback"), FragmentFeedbackScreen.class, null);


  }
}

And FragmentFeedbackScreen.java is as following :

import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


public class FragmentFeedbackScreen extends Fragment{

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // TODO Auto-generated method stub  

    //return super.onCreateView(inflater, container, savedInstanceState);

    Log.e("Fragment:", "VIEW");
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.fragment_feedback_screen, container, false);
}   

@Override
public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);             
}
@Override
public void onStart() {
    // TODO Auto-generated method stub
    super.onStart();        
    Log.e("Fragment:", "here");
}
}

fragment_feedback_screen.xml is given below :

<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:background="@color/background">

<TextView
    android:id="@+id/rateTextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="20dp"
    android:text="@string/rateUs" />

<RatingBar
    android:id="@+id/rattings"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/rateTextView"
    android:layout_below="@+id/rateTextView"
    android:layout_marginTop="20dp" />


<EditText
    android:id="@+id/emailId"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/rattings"
    android:layout_below="@+id/rattings"
    android:layout_marginTop="20dp"
    android:ems="10"
    android:hint="@string/emailId"
    android:inputType="textEmailAddress" />


<EditText
    android:id="@+id/message"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/emailId"
    android:layout_below="@+id/emailId"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="20dp"
    android:ems="10"
    android:hint="@string/write_your_message"
    android:inputType="textMultiLine" >

</EditText>

<Button
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/message"
    android:layout_alignParentBottom="true"
    android:layout_alignRight="@+id/message"
    android:layout_marginBottom="20dp"
    android:text="@string/sendMessage" />


 </RelativeLayout>

But when i click on tab of feedback,nothing is shown up in that view. what is wrong with this ?

Edit (LOGCAT log) :

 01-20 16:28:29.452: I/Adreno200-EGL(19888): <qeglDrvAPI_eglInitialize:290>: EGL 1.4 QUALCOMM build:  (Merge)
 01-20 16:28:29.452: I/Adreno200-EGL(19888): Build Date: 09/29/12 Sat
 01-20 16:28:29.452: I/Adreno200-EGL(19888): Local Branch: 
 01-20 16:28:29.452: I/Adreno200-EGL(19888): Remote Branch: 
 01-20 16:28:29.452: I/Adreno200-EGL(19888): Local Patches: 
 01-20 16:28:29.452: I/Adreno200-EGL(19888): Reconstruct Branch: 
 01-20 16:28:45.772: E/Fragment:(19888): here1
 01-20 16:28:45.772: E/Fragment:(19888): here
 01-20 16:28:47.202: E/Fragment:(19888): here1
 01-20 16:28:47.202: E/Fragment:(19888): here
 01-20 16:28:48.092: E/Fragment:(19888): here1
 01-20 16:28:48.092: E/Fragment:(19888): here

EDIT-2 (tabbar_layout.xml)

<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TabWidget
        android:id="@android:id/tabs"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/background"
        android:layout_alignParentBottom="true" />

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="0dp"
        android:layout_height="0dp" />

    <FrameLayout
        android:id="@+id/realtabcontent"
        android:layout_width="match_parent"
        android:layout_height="0dp" />

 </RelativeLayout> 
</android.support.v4.app.FragmentTabHost>
Uniruddh
  • 4,427
  • 3
  • 52
  • 86
  • 1
    Your code seems to be correct, is perfect similar to the example od android developers... Can you please see the logcat and reply about what lines of your log are printed? – phemt.latd Jan 20 '14 at 10:16
  • 1
    Actually i'm not getting any error, though i have added the logs. – Uniruddh Jan 20 '14 at 11:00
  • Can someone show me my mistake or any other solution? please, i am stuck here. :( – Uniruddh Jan 21 '14 at 10:16
  • ok, now i'm away from an android develop enviornment, when i come back home i try to run your code and debug it. I think that there is a problem with inflating layout or something similar because your code pass tot he onStart callback... – phemt.latd Jan 21 '14 at 10:52
  • That will be a very big help to me. – Uniruddh Jan 21 '14 at 10:54
  • 1
    No problem during my launch pause i can find some minutes to switch to my android env and try this very strange problem ;) – phemt.latd Jan 21 '14 at 11:13
  • 1
    I'm sorry for the time, i've tried exactly your code and it work well. The only code that i've write from my hand is the tabbar_layout.xml. Can you please edit your response and write this xml? can you please attach the manifest? If will be necessary i can send to you a zipped project working – phemt.latd Jan 22 '14 at 08:20
  • its fine, updated my question with both files. – Uniruddh Jan 22 '14 at 08:30
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/45770/discussion-between-phemt-latd-and-i-droid) – phemt.latd Jan 22 '14 at 08:36

1 Answers1

1

Ok the problem is on the tabbar_layout.xml Try with this one:

 <?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" >

<FrameLayout
    android:id="@+id/realtabcontent"
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="1" />

<android.support.v4.app.FragmentTabHost
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="0" />
</android.support.v4.app.FragmentTabHost>

</LinearLayout>
phemt.latd
  • 1,775
  • 21
  • 33