0

두 개의 탭이있는 TabLayout에 ViewPager를 사용하고 있습니다. 두 탭 모두 ExpandableListView가있는 레이아웃을 포함합니다. 앱의 첫 번째 시작시 ExpandableListViews가 올바르게 표시됩니다. 하지만 내가 다른 조각으로 변경하고 ExpandableListViews가 사라지면 반환하십시오.ExpandableListView가 다른 활동으로 변경 한 후 사라집니다.

나는 많은 것을 수색했지만이 부분을 제외하고는 아무 것도 발견되지 않았다. Link. 하지만 데이터 바인딩을 사용하고 있기 때문에 setContentView를 사용하지 않습니다.

다음은 현재 코드의 일부입니다. ViewPager

//Constructor to the class 
public CategoriesPagerAdapter(FragmentManager fm, int tabCount, Context context) { 
    super(fm); 
    //Initializing tab count 
    this.tabCount = tabCount; 
    this.context = context; 
} 

@Override 
public Fragment getItem(int position) { 
    //Returning the current tabs 
    switch (position) { 
     case 0: 
      return new Tab_Income(); 
     case 1: 
      return new Tab_Expense(); 
     default: 
      return new Tab_Income(); 
    } 
} 

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

@Override 
public CharSequence getPageTitle(int position) { 
    switch (position) { 
     case 0: 
      return context.getResources().getString(R.string.income_categories); 
     case 1: 
      return  context.getResources().getString(R.string.expense_categories); 
    } 
    return null; 
} 
} 

바인딩 최초의 탭의 ViewPager와

조각

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    > 
    <!-- TabLayout with two Tabs --> 
    <android.support.design.widget.TabLayout 
     android:id="@+id/tabLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     app:tabMode="fixed" 
     /> 

    <!-- ViewPager for swipe --> 
    <android.support.v4.view.ViewPager 
     android:id="@+id/pager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@id/tabLayout" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

</RelativeLayout> 

어댑터는 두 번째 탭은 동일한 코드를 또 다른 목록을 포함

첫째 ExpandableListView의
private FragmentIncomeCategoriesBinding binding; 
CategoriesAdapter expandableListAdapter; 
@Nullable 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    binding = DataBindingUtil.inflate(inflater, R.layout.fragment_income_categories, container, false); 
    expandableListAdapter = new CategoriesAdapter(getActivity(), GlobalLists.getInstance().getIncomeCategoriesMap()); 
    binding.expandableListViewIncome.setAdapter(expandableListAdapter); 
    return binding.getRoot(); 
} 
@Override 
public void onResume() { 
    super.onResume(); 
    expandableListAdapter = new CategoriesAdapter(getActivity(), GlobalLists.getInstance().getIncomeCategoriesMap()); 
    binding.expandableListViewIncome.setAdapter(expandableListAdapter); 
} 

레이아웃두 번째 레이아웃은 모두 ExpandableListViews

private Context context; 
ArrayMap<Category, List<Category>> categoryMap ; 

public CategoriesAdapter(Context context, ArrayMap<Category, List<Category>> categoryMap) { 
    this.context = context; 
    this.categoryMap = categoryMap; 
} 

@Override 
public int getGroupCount() { 
    return categoryMap.size(); 
} 

@Override 
public int getChildrenCount(int listPosition) { 
    return categoryMap.valueAt(listPosition).size(); 
} 

@Override 
public Object getGroup(int listPosition) { 
    return categoryMap.valueAt(listPosition); 
} 

@Override 
public Object getChild(int listPosition, int expandedListPosition) { 
    return categoryMap.valueAt(listPosition).get(expandedListPosition); 
} 

@Override 
public long getGroupId(int listPosition) { 
    return listPosition; 
} 

@Override 
public long getChildId(int listPosition, int expandedListPosition) { 
    return categoryMap.valueAt(listPosition).get(expandedListPosition).getId(); 
} 

@Override 
public boolean hasStableIds() { 
    return false; 
} 

@Override 
public View getGroupView(int listPosition, boolean isExpanded, View convertView, ViewGroup parent) { 
    CategoryListParentBinding parentBinding = DataBindingUtil.inflate(
      LayoutInflater.from(parent.getContext()), 
      R.layout.category_list_parent, parent, false); 
    parentBinding.setParentCategory(categoryMap.keyAt(listPosition)); 
    return parentBinding.getRoot(); 
} 

@Override 
public View getChildView(int listPosition, int expandedListPosition, boolean isLastChild, View convertView, ViewGroup parent) { 
    CategoryListChildBinding childBinding = DataBindingUtil.inflate(
      LayoutInflater.from(parent.getContext()), 
      R.layout.category_list_child, parent, false); 
     childBinding.setChildCategory(categoryMap.valueAt(listPosition).get(expandedListPosition)); 
    return childBinding.getRoot(); 
} 

@Override 
public boolean isChildSelectable(int i, int i1) { 
    return true; 
} 

내가 가지고 있기 때문에 사람이 도움을 줄 수 U 희망에 대한

<layout xmlns:android="http://schemas.android.com/apk/res/android" 
> 
<ExpandableListView 
    android:id="@+id/expandableListView_expense" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:indicatorLeft="?android:attr/expandableListPreferredItemIndicatorLeft" 
    android:divider="@android:color/darker_gray" 
    android:dividerHeight="0.5dp" /> 
</layout> 

어댑터 대 동일한 코드를입니다 어떻게해야할지 모르겠다.

업데이트 : 위의 코드에서 오류가 발견되었습니다. ViewPager가 포함 된 프래그먼트를 시작하는 방법이었습니다.

잘못된 전화 :

 CategoriesPagerAdapter adapter = new CategoriesPagerAdapter(getActivity().getFragmentManager() 
      , 2, getActivity()); 

오른쪽 호출 :

 CategoriesPagerAdapter adapter = new CategoriesPagerAdapter(getChildFragmentManager() 
      , 2, getActivity()); 

답변

0

나 자신에 의해 문제를 해결했습니다. 만약 누군가가 같은 문제가 있다면 해결책입니다.

잘못된 전화 :

 CategoriesPagerAdapter adapter = new CategoriesPagerAdapter(getActivity().getFragmentManager() 
      , 2, getActivity()); 

오른쪽 전화 :

 CategoriesPagerAdapter adapter = new CategoriesPagerAdapter(getChildFragmentManager() 
      , 2, getActivity()); 
관련 문제