gpt4 book ai didi

android - 自定义可扩展的 BaseExpandableListAdapter getGroupView 或 getChildView 永远不会被调用

转载 作者:行者123 更新时间:2023-11-30 02:17:22 25 4
gpt4 key购买 nike

我有一个包含 2 个页面的 Viewpager,在第 1 页我填写了一个表单并滑动到第 2 页,其中包含 expandableList,我正在使用如下自定义适配器.

我在布局中包含了可扩展的 listview 和另一个按钮。

当我滑动到这个新页面时,我看到了空布局和按钮,可扩展列表从未显示。

我已经检查并发现 getGroupCount 返回的大小等于 arrayList 数据的大小。所以不是数据为空的问题。

在进一步分析中,我发现 getGroupView 以及 getChildView 永远不会被调用,我添加了一些日志语句来调试这些方法,它们永远不会被打印出来.但是构造函数被调用,getGroupCoun 也返回正确的值。我的实现是否正确?

public class FareStageExpandableListAdapter extends BaseExpandableListAdapter

{
private Context context;
private LayoutInflater inflater;
private ArrayList<TripTimings> data;
private SimpleDateFormat formatter;
private EditText fareField;
private TextView headerText;
private TextView childText;

public FareStageExpandableListAdapter(Context context,
ArrayList<TripTimings> data)
{
Log.d("FareStageExADapter", "Constructor called");
this.context = context;
this.inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.data = data;
this.formatter = new SimpleDateFormat("HH:mm");

}

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

@Override
public int getChildrenCount(int groupPosition)
{
return data.size() - 1 - groupPosition;
}

@Override
public Object getGroup(int groupPosition)
{
return data.get(groupPosition);
}

@Override
public Object getChild(int groupPosition, int childPosition)
{
return data.get(groupPosition + childPosition);
}

@Override
public long getGroupId(int groupPosition)
{
return data.get(groupPosition).hashCode();
}

@Override
public long getChildId(int groupPosition, int childPosition)
{
return data.get(groupPosition + childPosition).hashCode() + 5;
}

@Override
public boolean hasStableIds()
{
// TODO Auto-generated method stub
return true;
}

@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parentView)
{
TripTimings parent = data.get(groupPosition);
if (convertView == null)
{
convertView = inflater.inflate(R.layout.fareadd_expanded_parent,
parentView, false);
}
headerText = ((TextView) convertView.findViewById(R.id.originText));

Log.d("Setting header text ", parent.getStop().getStop_name());
headerText.setText(parent.getStop().getStop_name());
return convertView;
}

@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup childView)
{
final TripTimings child = data.get(groupPosition + childPosition);
if (convertView == null)
{
convertView = inflater.inflate(R.layout.fareadd_expanded_child,
childView, false);
}
childText = ((TextView) convertView.findViewById(R.id.destinationText));

Log.d("Setting child text ", child.getStop().getStop_name());
childText.setText(child.getStop().getStop_name());

return convertView;
}

@Override
public boolean isChildSelectable(int groupPosition, int childPosition)
{
// TODO Auto-generated method stub
return false;
}

最佳答案

这就是当您 sleep 不足时会发生的情况。代码没有任何问题,只是 Adapter 从未添加到 expandablelistview

关于android - 自定义可扩展的 BaseExpandableListAdapter getGroupView 或 getChildView 永远不会被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29081493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com