0

Currently I am trying to create somethine like this in xml. User able to scroll the whole page instead of listview only. Anyone got idea how to create this XML or any suggestion use what to replace list view.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="plaza_semanggi.lippomalls.lippoapp.Screens.HomeFragment"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width ="wrap_content"
    android:layout_height ="wrap_content"
    card_view:cardCornerRadius= "5dp"
    android:layout_weight="5"

    >
    <android.support.v4.view.ViewPager
        android:id="@+id/home_viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

</android.support.v7.widget.CardView>

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="5"></ListView>


</LinearLayout>

enter image description here

2
  • I don't know why are you trying to do this if the whole page gonna scroll it won't look good.at all. Commented Oct 28, 2015 at 6:42
  • U can use this type of method after setAdapter stackoverflow.com/questions/18367522/… Commented Oct 28, 2015 at 6:47

2 Answers 2

1

Don't use Scrollview ....Only use ListView and Create two view first for viewpager and second for your list item view. Add Viewpager view in first row of listview and remaining for list item.

Use following changes in adapter

@Override
public int getItemViewType(int position) {
    // TODO Auto-generated method stub

    boolean strViewPagerFlage=arraylist.get(position).getviewpageflage();
    //get 
    if(strViewPagerFlage){  
    //For ViewPager
    return 0;   
    }else{
    //For ListItem
      return 1;
    }

}

@Override
public int getViewTypeCount() {
    // TODO Auto-generated method stub
    return 2;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub

    View view = convertView;
     if(position == 0){
        view = inflater.inflate(R.layout.view_pager_layout, null);
    }else{
        view = inflater.inflate(R.layout.list_item, null);
    }

}
Sign up to request clarification or add additional context in comments.

Comments

0

One possibility is to put your whole stuff in the Listview. The first position of your list adapter would return the CardView with the Viewpager and the following positions return your other list entries.

2 Comments

how would i know the position ? any link to recommend for me to read up ?
I think this is straight forward. But stackoverflow.com/a/33384727/2960788 gives you an idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.