Skip to content
This repository has been archived by the owner on Jun 4, 2019. It is now read-only.

ViewPager on content view doesn't show anything #50

Open
vuongggg opened this issue Mar 4, 2015 · 2 comments
Open

ViewPager on content view doesn't show anything #50

vuongggg opened this issue Mar 4, 2015 · 2 comments

Comments

@vuongggg
Copy link

vuongggg commented Mar 4, 2015

Hello, i am trying to add a ViewPager to content view but it doesn't show anything and i can even see the action view behind content.
Here is a picture of what i got
untitled1

Could you tell me what is the problem and how can i fix that?
Thanks you!

@StevenRudenko
Copy link
Owner

it seems you've done something wrong with layouts or viewpager logic. please provide some code here so I can help you.

@vuongggg
Copy link
Author

vuongggg commented Mar 4, 2015

Thanks you for replying so quickly
Here is my code.

My activity:

public class Activity_topic_detail extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setContentFragment();
        actionsContentView = (ActionsContentView) findViewById(R.id.actionsContentView);
        actionsContentView.showContent();
    }

    public void updateContent() {
        final FragmentManager fm = getSupportFragmentManager();
        final FragmentTransaction tr = fm.beginTransaction();
        viewpagerFragment fragment = new viewpagerFragment();

        tr.replace(R.id.content_main, fragment, "detail");
        ft.show(fragment);
        ft.commit();
    }
}

My viewPagerFragment class:

public class viewpagerFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.viewpager_fragment, container, false);
        ViewPager viewPager = (ViewPager) rootView.findViewById(R.id.topic_item_viewPager);
        viewPagerAdapter adapter = new viewPagerAdapter(getActivity().getApplicationContext());
        viewPager.setAdapter(adapter);
        return rootView;
    }
}

viewPagerAdapter class:

public class viewPagerAdapter extends PagerAdapter {

    Context mContext;

    public viewPagerAdapter(Context context){
        super();
        mContext = context;
    }

    @Override
    public int getCount() {
        return 4;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View v = new View(mContext);
        LayoutInflater inflate = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        switch (position) {
            case 0: v = inflater.inflate(R.layout.topic_detail_tab_dialog, null);
            case 1: v = inflater.inflate(R.layout.topic_detail_tab_vocabulary, null);
            case 2: v = inflater.inflate(R.layout.topic_detail_tab_highest_score, null);
            case 3: v = inflater.inflate(R.layout.topic_detail_tab_comment, null);
        }
        ((ViewPager) container).addView( v ,position);
        return v;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        super.destroyItem(container, position, object);
    }
}

activity_main.xml

<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <shared.ui.actionscontentview.ActionsContentView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        app:actions_layout="@layout/layout_menu"
        app:content_layout="@layout/home_fragment"
        android:id="@+id/actionsContentView"
        app:spacing="43dip"
        app:actions_spacing="0dp"
        app:fling_duration="900"
        app:shadow_drawable="@drawable/divider_vertical_left_menu"
        app:shadow_width="2dip"
        app:spacing_type="right_offset"
        app:swiping_type="full"
        android:focusable="false"/>
</RelativeLayout>

home_fragment.xml

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <RelativeLayout android:layout_width="fill_parent"
        android:layout_height="45dip"
        android:background="#ff617417">
        <ImageButton android:layout_width="45dip"
            android:layout_height="45dip"
            android:background="@drawable/btn_slider_menu"
            android:scaleType="centerCrop"
            android:id="@+id/btn_slide_menu"
            android:layout_margin="0dip"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:onClick="onClick"/>
        <ImageView android:layout_width="130dp"
            android:layout_height="wrap_content"
            android:scaleType="fitCenter"
            android:id="@+id/top_logo"
            android:layout_centerInParent="true" />
        <ImageView android:layout_width="40dip"
            android:layout_height="40dip"
            android:src="@drawable/ico_play"
            android:scaleType="centerCrop"
            android:id="@+id/btn_play"
            android:layout_margin="2.5dip"
            android:layout_alignParentRight="true"
            android:visibility="invisible"/>
    </RelativeLayout>

    <FrameLayout
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:id="@+id/content_main"/>
</LinearLayout>

viewPager_fragment.xml

<android.support.v4.view.ViewPager
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/topic_item_viewPager"/>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants