ОБРАЗЕЦ ОБНОВЛЕНИЯ
Моя цель - реализовать viewpager в ExpandableListView. Я попытался закодировать это, но это не показывает. Я также пытался реализовать это под ScrollView, чтобы проверить что-то и тот же результат. Я думаю, это из-за 2 прокручиваемых макета одновременно? К настоящему времени я нашел решение для ScrollView с viewpager. Когда я добавил android: fillViewport = "true" , это сработало, и теперь я могу видеть внутри него пейджер.
Как я могу реализовать viewpager в ExpandableListView? У него нет android: fillViewport = true "" , что я могу использовать кроме него?
Вот макеты XML.
Здесь я должен добавить свой пейджер
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="37"
android:background="@color/whiteWithAlpha75">
<ExpandableListView
android:minWidth="25px"
android:minHeight="25px"
android:childDivider="@drawable/childSeparator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="1dp"
android:id="@+id/expandableListView" />
</LinearLayout>
Это мой ExpandableListAdapter
using System;
using System.Collections.Generic;
using Android.App;
using Android.Views;
using Android.Widget;
using Android.Graphics;
using ENTITIES;
using System.Linq;
using Android.Support.V4.Content;
using Android.Support.V4.View;
namespace H2POS
{
class CategoryItemExpandableAdapter : BaseExpandableListAdapter
{
private Activity activity;
private List<ENT_DataEntries> categoryList;
List<ViewPager> viewPagerList;
public CategoryItemExpandableAdapter(Activity activity, List<ENT_DataEntries> categoryList, List<ViewPager> viewPagerList) : base()
{
this.activity = activity;
this.categoryList = categoryList;
this.viewPagerList = viewPagerList;
}
public override int GroupCount
{
get
{
return categoryList.Count;
}
}
public override bool HasStableIds
{
get
{
return true;
}
}
public override Java.Lang.Object GetChild(int groupPosition, int childPosition)
{
return childPosition;
}
public override long GetChildId(int groupPosition, int childPosition)
{
return childPosition;
}
public override int GetChildrenCount(int groupPosition)
{
return 1;
}
public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
{
try
{
var row = convertView;
if (row == null)
{
row = LayoutInflater.From(activity).Inflate(Resource.Layout.Layout_LinearVertical, null);
LinearLayout llLinearViewPager = row.FindViewById<LinearLayout>(Resource.Id.llLinearViewPager);
//This is for testing. This is showing
TextView tvSample = new TextView(activity);
tvSample.SetHeight(50);
tvSample.SetWidth(50);
tvSample.Text = "Sample";
llLinearViewPager.AddView(tvSample);
//This is my view pager. This is not showing
//I tried to attach it to other layout and it is showing there
if(viewPagerList[groupPosition].Parent == null)
llLinearViewPager.AddView(viewPagerList[groupPosition]);
}
return row;
}
catch (Exception e)
{
UIHelper.ToastMessage(activity.BaseContext, "Error on expandable adapter");
}
return new View(activity);
}
public override Java.Lang.Object GetGroup(int groupPosition)
{
throw new NotImplementedException();
}
public override long GetGroupId(int groupPosition)
{
return groupPosition;
}
public override View GetGroupView(int groupPosition, bool isExpanded, View convertView, ViewGroup parent)
{
View row = convertView;
if (row == null)
{
row = LayoutInflater.From(activity).Inflate(Resource.Layout.Layout_Category, null);
}
//set header text
TextView categoryHeader = row.FindViewById<TextView>(Resource.Id.tvCategoryName);
categoryHeader.Text = categoryList[groupPosition].Description;
categoryHeader.SetTypeface(Typeface.Default, TypefaceStyle.Bold);
if (isExpanded)
categoryHeader.SetBackgroundColor(new Color(ContextCompat.GetColor(activity, Resource.Color.baseColorLightWithAlpha10)));
else
categoryHeader.SetBackgroundColor(new Color(ContextCompat.GetColor(activity, Resource.Color.whiteWithAlpha10)));
return row;
}
public override bool IsChildSelectable(int groupPosition, int childPosition)
{
return true;
}
}
}
Здесь мне удается показать пейджер под ScrollView. Я добавил видовой пейджер под llItemSelectedArea
<ScrollView
android:id="@+id/scrollItemSelectedArea"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="95"
android:paddingBottom="-65dp"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:background="@color/whiteWithAlpha15">
<LinearLayout
android:id="@+id/llItemSelectedArea"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="65dp" />
</ScrollView>