android 行列表,android消耗品列表

我需要创建可扩展列表的列表。问题是可展开列表的高度是一行。看起来是这样的:

30f6f30b0ddb30857ce44f3354e3da4b.png

如果我将高度硬编码为300dp,它将如下所示:

66aeff38eba8d7c675451d717841c336.png

这是我的代码(我删除了一些多余的信息):

public class AllQuestionsListAdapter extends BaseAdapter{

private final ArrayList questionsList;

private final LayoutInflater mInflater;

private final Context context;

public AllQuestionsListAdapter(ArrayList questionsList, Context context) {

this.questionsList = questionsList;

this.context = context;

this.mInflater = LayoutInflater.from(context);

}

@Override

public View getView(int position, View convertView, ViewGroup parent) {

View rowView = mInflater.inflate(R.layout.all_question_list_item, null);

ViewHolder vh = new ViewHolder();

vh.theme = rowView.findViewById(R.id.aq_item_list_theme);

vh.theme.setText(questionsList.get(position).getTheme());

vh.listView = rowView.findViewById(R.id.aq_item_list_questions);

QuestionsExpandableListAdapter adapter = new QuestionsExpandableListAdapter(context, questionsList.get(position));

vh.listView.setAdapter(adapter);

return rowView;

}

static class ViewHolder{

TextView theme;

ExpandableListView listView;

}

}

public class QuestionsExpandableListAdapter implements ExpandableListAdapter {

private Context context;

private QuestionsList questionsList;

public QuestionsExpandableListAdapter(Context context, QuestionsList questionsList){

this.context = context;

this.questionsList = questionsList;

}

@Override

public Object getGroup(int groupPosition) {

return questionsList.getQuestions().get(groupPosition).getQuestion();

}

@Override

public Object getChild(int groupPosition, int childPosition) {

return questionsList.getQuestions().get(groupPosition).getAnswer();

}

@Override

public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

String headerInfo = (String) getGroup(groupPosition);

if (convertView == null) {

LayoutInflater inf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

convertView = inf.inflate(R.layout.group_items, null);

}

TextView heading = convertView.findViewById(R.id.heading);

heading.setText(headerInfo);

return convertView;

}

@Override

public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {

String detailInfo = (String) getChild(groupPosition, childPosition);

if (convertView == null) {

LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

convertView = infalInflater.inflate(R.layout.child_items, null);

}

TextView childItem = convertView.findViewById(R.id.childItem);

childItem.setText(detailInfo);

return convertView;

}

}

所有问题列表.xml:

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="300dp">

android:id="@+id/aq_item_list_theme"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginStart="8dp"

android:layout_marginTop="8dp"

android:text="aaaaaaaaaaaa"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent" />

android:id="@+id/aq_item_list_questions"

android:layout_width="0dp"

android:layout_height="300dp"

android:layout_marginEnd="8dp"

android:layout_marginStart="8dp"

android:layout_marginTop="8dp"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.0"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/aq_item_list_theme">

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值