Question

I am using actionbarsherlock library to have action-bar in my application,

I am also using view-pager to switch between the page,

Now the problem is i want only one tab with two fragment to display data regarding each other.

What could be the possible way to do this?

I have been going through like the one below but unsuccessful

In main fragment i am inflating a xml like this

<code>
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View fragView = inflater.inflate(R.layout.album_view_main, container, false);

        return fragView;
    }
</code>

xml fie is look like this

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

    <fragment
        android:id="@+id/fragment_album_view"
        android:layout_width="0px"
        android:layout_height="fill_parent"
        android:layout_weight="3"
        class="com.nix.music.activity.fragments.AlbumFragMent" />

    <FrameLayout
        android:id="@+id/frame_list_song"
        android:layout_width="0px"
        android:layout_height="fill_parent"
        android:layout_weight="2" >
    </FrameLayout>
</LinearLayout>
</code>

but the problem is i cannot find "frame_list_song" in AlbumFragment class it appears null

what could be the way around ?

thank you

Was it helpful?

Solution

This layout should be set in the parent activity using setContentView(). Then, you would be able to do something like getActivity().findViewById(R.id.frame_list_song) from your AlbumFragment. The better way would be to use an interface and transfer control to the main activity, and not access other fragments directly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top