ExpandableView inside another ExpandableView will not inflate children

I struggled a couple of weeks to solve this problem. I have two extensible views, one inside the other. Whenever I click on extensible second-level viewing elements, it will not inflate its children. All I see when I click is a small scroll bar that appears on the right side in the most extensible view element. Using a simple layout with a fixed textview leads to the same behavior, which means that the problem is not in the / s ShiftListItem object.

In addition, getChildView () has never been called.

This is the small scroll bar that appears for a second

YearListAdapter:

package com.dg.android.salarycalculator.adapter; import java.util.ArrayList; import java.util.Calendar; import com.dg.android.salarycalculator.R; import com.dg.android.salarycalculator.Salary; import com.dg.android.salarycalculator.views.MonthsListView; import android.content.Context; import android.util.SparseArray; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseExpandableListAdapter; import android.widget.TextView; public class YearListAdapter extends BaseExpandableListAdapter { private Context _context; private SparseArray<SparseArray<ArrayList<Salary>>> _shiftYears; public YearListAdapter( SparseArray<SparseArray<ArrayList<Salary>>> shiftYears, Context context) { super(); _context = context; _shiftYears = shiftYears; } public Object getChild(int arg0, int arg1) { return (null == _shiftYears.get(_shiftYears.keyAt(arg0))) ? null : _shiftYears.get(_shiftYears.keyAt(arg0)).get( _shiftYears.get(_shiftYears.keyAt(arg0)).keyAt(arg1)); } public long getChildId(int arg0, int arg1) { return arg1; } public View getChildView(int arg0, int arg1, boolean arg2, View convertView, ViewGroup arg4) { MonthsListView monthLevelExpandable = new MonthsListView(_context); MonthListAdapter adapter = new MonthListAdapter(_context, _shiftYears.get(_shiftYears.keyAt(arg0))); monthLevelExpandable.setAdapter(adapter); adapter.forceReload(); monthLevelExpandable.setGroupIndicator(null); return monthLevelExpandable; } public int getChildrenCount(int arg0) { if (null == _shiftYears.get(_shiftYears.keyAt(arg0))) return 0; return _shiftYears.get(_shiftYears.keyAt(arg0)).size(); } public Object getGroup(int arg0) { return (null == _shiftYears) ? null : _shiftYears.get(_shiftYears .keyAt(arg0)); } public int getGroupCount() { return _shiftYears.size(); } public long getGroupId(int arg0) { return arg0; } public View getGroupView(int arg0, boolean isExpanded, View convertView, ViewGroup arg3) { if (convertView == null) { LayoutInflater inflater = (LayoutInflater) _context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.year_list_view_item, null); } TextView title = (TextView) convertView.findViewById(R.id.yearTitle); title.setText("" + _shiftYears.keyAt(arg0)); return convertView; } public boolean hasStableIds() { return true; } public boolean isChildSelectable(int arg0, int arg1) { return true; } public void forceReload() { notifyDataSetChanged(); } } 

MonthListAdapter:

 package com.dg.android.salarycalculator.adapter; import java.util.ArrayList; import java.util.Calendar; import com.dg.android.salarycalculator.R; import com.dg.android.salarycalculator.Salary; import com.dg.android.salarycalculator.views.ShiftListItem; import android.content.Context; import android.util.SparseArray; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseExpandableListAdapter; import android.widget.TextView; public class MonthListAdapter extends BaseExpandableListAdapter { private Context _context; private SparseArray<ArrayList<Salary>> _shiftMonths; public MonthListAdapter(Context context, SparseArray<ArrayList<Salary>> shiftMonths) { super(); _context = context; _shiftMonths = shiftMonths; } public Object getChild(int groupPosition, int childPosition) { return (null == _shiftMonths) ? null : _shiftMonths.get( _shiftMonths.keyAt(groupPosition)).get(childPosition); } public long getChildId(int groupPosition, int childPosition) { return childPosition; } public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { ShiftListItem sli; if (null == convertView) { sli = (ShiftListItem) View.inflate(_context, R.layout.shift_list_item, null); } else { sli = (ShiftListItem) convertView; } sli.setSalary(_shiftMonths.get(_shiftMonths.keyAt(groupPosition)).get( childPosition)); return sli; } public int getChildrenCount(int groupPosition) { if (null == _shiftMonths || null == _shiftMonths.get(_shiftMonths.keyAt(groupPosition))) return 0; return _shiftMonths.get(_shiftMonths.keyAt(groupPosition)).size(); } public Object getGroup(int groupPosition) { return (null == _shiftMonths) ? null : _shiftMonths.get(_shiftMonths .keyAt(groupPosition)); } public int getGroupCount() { return _shiftMonths.size(); } public long getGroupId(int groupPosition) { return groupPosition; } public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { if (convertView == null) { LayoutInflater inflater = (LayoutInflater) _context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.month_list_view_item, null); } TextView title = (TextView) convertView.findViewById(R.id.monthTitle); title.setText("" + _shiftMonths.keyAt(groupPosition)); return convertView; } public boolean hasStableIds() { return true; } public boolean isChildSelectable(int groupPosition, int childPosition) { return true; } public void forceReload() { notifyDataSetChanged(); } } 

ShiftListItem:

  package com.dg.android.salarycalculator.views; import java.util.Calendar; import com.dg.android.salarycalculator.R; import com.dg.android.salarycalculator.Salary; import android.content.Context; import android.util.AttributeSet; import android.widget.LinearLayout; import android.widget.TextView; public class ShiftListItem extends LinearLayout { private Salary salary; private TextView itemTimeAndDate; private TextView itemCashView; public ShiftListItem(Context context, AttributeSet attrs) { super(context, attrs); salary = new Salary(); } @Override protected void onFinishInflate() { super.onFinishInflate(); itemTimeAndDate = (TextView) findViewById(R.id.itemTimeAndDate); itemCashView = (TextView) findViewById(R.id.itemCashView); } public void setSalary(Salary salary) { this.salary = salary; Calendar start = salary.getShiftTime().getStart(); Calendar end = salary.getShiftTime().getEnd(); int tHour; int tMinute; int tSec; tSec = salary.getShiftTime().getDifference( salary.getShiftTime().getStart(), salary.getShiftTime().getEnd()); tHour = tSec / 3600; tSec -= tHour * 3600; tMinute = tSec / 60; tSec -= tMinute * 60; itemTimeAndDate.setText("Time: (Start) " + returnTwoDigitString(start.get(Calendar.HOUR_OF_DAY)) + ":" + returnTwoDigitString(start.get(Calendar.MINUTE)) + " (End)" + returnTwoDigitString(end.get(Calendar.HOUR_OF_DAY)) + ":" + returnTwoDigitString(end.get(Calendar.MINUTE)) + "\n" + (start.get(Calendar.DAY_OF_MONTH)) + "-" + (end.get(Calendar.DAY_OF_MONTH)) + "/" + (start.get(Calendar.MONTH) + 1) + "-" + (end.get(Calendar.MONTH) + 1) + "/" + start.get(Calendar.YEAR) + "-" + end.get(Calendar.YEAR)); itemCashView.setText(salary.getCash() + " " + salary.getCurrency() + " Total Time Of: " + returnTwoDigitString(tHour) + ":" + returnTwoDigitString(tMinute) + ":" + returnTwoDigitString(tSec)); } public Salary getSalary() { return salary; } private String returnTwoDigitString(int time) { if (time < 10) { return "0" + time; } return "" + time; } } 

shift_list_item.xml:

 <?xml version="1.0" encoding="utf-8"?> <com.dg.android.salarycalculator.views.ShiftListItem xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/itemTimeAndDate" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textIsSelectable="false" /> <TextView android:id="@+id/itemCashView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textIsSelectable="false" /> </com.dg.android.salarycalculator.views.ShiftListItem> 
+1
source share
1 answer

I added the following code:

 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { widthMeasureSpec = MeasureSpec .makeMeasureSpec(960, MeasureSpec.AT_MOST); heightMeasureSpec = MeasureSpec.makeMeasureSpec(600, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } 

and also added the following fields: int intGroupPosition, intChildPosition, intGroupid;

to all my ExpandableListView classes (of course, use your own input), and now it works!

0
source

Source: https://habr.com/ru/post/1496210/


All Articles