0
MyListFragment.java this extends ListFragment and onListItemClick() I need to migrate to another two Fragments which should be displayed over this ListFragment.

I don't know how to solve this error I am stuck over for 3 days help me out. I don't get any sort of error which can be logged and displayed, It has become impossible.

public void onListItemClick(ListView l, View v, int position, long id) {

        Log.d("ListCLicked","Yes Clicked");

        //String clickedDetail = (String)l.getItemAtPosition(position);

            /*
             * The second fragment not yet loaded. 
             * Load MyDetailFragment by FragmentTransaction, and pass 
             * data from current fragment to second fragment via bundle.
             */
            MyDetailFragment myDetailFragment = new MyDetailFragment();
            Bundle bundle = new Bundle();
            //bundle.putString("KEY_DETAIL", clickedDetail);
            myDetailFragment.setArguments(bundle);
            Log.d("ListCLicked1","Yes Clicked");
            FragmentTransaction fragmentTransaction =
                    getChildFragmentManager().beginTransaction();
            Log.d("ListCLicked2","Yes Clicked");
            fragmentTransaction.add(R.id.tablistfragment, new MyDetailFragment());
            Log.d("ListCLicked3","Yes Clicked");
            fragmentTransaction.commit();


    }

MyDetailFragment.java is Fragment that an inflate to detailfragment.xml containg two fragments to be overlapped over the MyListFragment. MyListFragment is containg loaders and which log my phonebook contacts and form a list out of them on click of any List Item I need to get the fragment containing the details about the contact.Help Help Help Help help Help!!!!!!!!!

package com.example.crush_crm;

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





public class MyDetailFragment extends Fragment {


    ContactDetails con;

    public String number,callnumber,phn,emailtext;
    View view;

    public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState)
    {

        Log.d("MyDetailFragment1","Here it is");
        if (android.os.Build.VERSION.SDK_INT > 9) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }
        view=inflater.inflate(R.layout.detailfragment, null);

        Log.d("MyDetailFragment","Here it is");




        return view ;

    }   

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);


    }


}

MyDetailActivity extends FragmentActivity initialising the Tabhost and Viewpager.This activity doesn't get called when I execute even gives no error.I execute ContactHistory which inflates tablayout.xml , where I specify tools:context=".MyDetailACtivity" 



import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.Log;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;







public class MyDetailActivity extends FragmentActivity implements OnTabChangeListener,OnPageChangeListener{

    public ContactHistory his;

    ContactDetails con;

    public String number,callnumber,phn,emailtext;


    public void OnCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);


        Log.d("hiiiiiiii i m in ","main");
        his=(ContactHistory)getSupportFragmentManager().findFragmentById(R.id.oppofragment);
        his.mTabHost1.setup();


        MyDetailActivity.AddTab(this, his.mTabHost1, his.mTabHost1.newTabSpec("History").setIndicator("History"));
        MyDetailActivity.AddTab(this, his.mTabHost1, his.mTabHost1.newTabSpec("Opportunity").setIndicator("Opportunity"));

        his.mAdapter = new TabsPagerAdapter(this.getSupportFragmentManager());
        // Fragments and ViewPager Initialization
        Log.d("Tabs Added1 ","Done");

       his.mViewPager1.setAdapter(his.mAdapter);
       his.mViewPager1.setOnPageChangeListener(MyDetailActivity.this);
       Log.d("Tabs Added2 ","Done");
       his.mTabHost1.setOnTabChangedListener(this);

    }


    private static void AddTab(MyDetailActivity activity, TabHost tabHost, TabHost.TabSpec tabSpec) {
        tabSpec.setContent(new MyTabFactory(activity));
        tabHost.addTab(tabSpec);
    }
    public void onTabChanged(String tag) {
        int pos = his.mTabHost1.getCurrentTab();
        his.mViewPager1.setCurrentItem(pos);
    }
    @Override
    public void onPageScrollStateChanged(int arg0) {
    }

    // Manages the Page changes, synchronizing it with Tabs
    @Override
    public void onPageScrolled(int arg0, float arg1, int arg2) {
        int pos = his.mViewPager1.getCurrentItem();
        his.mTabHost1.setCurrentTab(pos);
    }

    @Override
        public void onPageSelected(int arg0) {
    }
    public void CallAct(View v)
    {
        Log.d("Hiiiiiiii","i m in main");
        con=(ContactDetails)getSupportFragmentManager().findFragmentById(R.id.contactfragment);

        number=con.phone.getText().toString();
        Log.d("Phone Number",number);
         callnumber="tel:"+number;
                Log.d("Phone Number",callnumber);

                Intent callButton=new Intent(Intent.ACTION_CALL,Uri.parse(callnumber));
                Log.d("Not Working","Intent Issue");
                startActivity(callButton);





        }

    public void MailAct(View v)
    {
        con=(ContactDetails)getSupportFragmentManager().findFragmentById(R.id.contactfragment);
        emailtext=con.textemail.getText().toString();

                Intent emailIntent=new Intent(Intent.ACTION_SEND);
                emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {emailtext});
                emailIntent.setType("message/rfc822");
                startActivity(emailIntent);



        }


}

ContactHistory.java ContactHistory just gives an inflate call to the tablayout and finds the ids for the tabhost and viewpagers.



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

public class ContactHistory extends Fragment {

    View view;
    public TabsPagerAdapter mAdapter;
    public ViewPager mViewPager;
    public TabHost mTabHost;

    public View onCreateView(LayoutInflater inflator,ViewGroup container,Bundle saveInstanceState)
    {
        Log.d("ContactHistory","History Oppurutnity");
        view=inflator.inflate(R.layout.tablayout,container,false);
        Log.d("onCreateView","Here I m OKKKKKKKKKKKKKKKKKKKKKKKKKK");
        if (android.os.Build.VERSION.SDK_INT > 9) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }

        mViewPager = (ViewPager)view.findViewById(R.id.viewpager);
        mTabHost = (TabHost) view.findViewById(android.R.id.tabhost);
        Log.d("I m not ohk","I go from here");
        return view;
    }

}

tablayout.xml this layout I used in another project works very fine without any problem even it gets displayed but here I need to overlap it over the Listfragment.
<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"
    tools:context=".MainActivity" >

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:orientation="horizontal" />

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

            <android.support.v4.view.ViewPager
                android:id="@+id/viewpager"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="top" />
        </LinearLayout>
    </TabHost>

</RelativeLayout>

detailfragment.xml contains the two fragments the ContactDetails fragment works very fine but the fragment ContactHistory with tabhost and ViewPager doesn't get displayed and I also don't get any error
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <fragment
        android:id="@+id/contactfragment"
        android:name="com.example.crush_crm.ContactDetails"
        android:layout_width="match_parent"
        android:layout_height="230dp"
         />

    <fragment
        android:id="@+id/oppofragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/contactfragment"
        class="com.example.crush_crm.ContactHistory" />

</RelativeLayout>

I don't get any error but my Fragment oppofragment doesnt get displayed where as when I try to dispaly the contactfragment it gets displayed.

1 Answers1

0

From what I understand, it may be because of nested fragments.

Nested fragments are not really a good way to work your problems out. You'd better use custom views : extend a Linear/RelativeLayout, and put your stuff in it.

Change

public class MyDetailFragment extends Fragment {

to

public class MyDetailView extends LinearLayout {

And some other adjustments if needed

You then don't need to use the Fragment manager, you can add your MyDetailView via xml or programmatically as you wish.

Hope it helps

Mathieu de Brito
  • 2,536
  • 2
  • 26
  • 30
  • Yes I do use nested Fragments but can you please explain what you mean in above suggestion.. – Snehal Tikone Feb 24 '15 at 14:56
  • Please Give me some Solution – Snehal Tikone Feb 25 '15 at 13:07
  • if this doesn't work for you, it means you have a layout issue : your layout may be not displayed at all, or too much on a side (outside the screen, or behind something) Anyway, working with custom views is no matter what the better way to solve your issue – Mathieu de Brito Feb 26 '15 at 13:16