gpt4 book ai didi

java - android studio ExpandableListAdapter 上下文错误

转载 作者:太空宇宙 更新时间:2023-11-04 13:25:54 26 4
gpt4 key购买 nike

这是我的 ListAdapter 编码,我的错误出在 png 图像文件的上下文上。如果我没有错我的背景我必须改变一些东西?但我不知道要改变什么

/image/MhEWr.png

package com.example.user.myapplication;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import java.util.HashMap;
import java.util.List;

public class MyExpandableListAdapter extends BaseExpandableListAdapter {

private Context context;
private List<String> listGroup;
private HashMap<String, List<String>> listChild;

public MyExpandableListAdapter(Context context, List<String> listGroup,
HashMap<String, List<String>> listChild) {
this.context = context;
this.listGroup = listGroup;
this.listChild = listChild;
}

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

@Override
public int getChildrenCount(int groupPosition) {
return listChild.get(listGroup.get(groupPosition)).size();
}

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

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

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

@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}

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

@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.group_layout, null);
}

String textGroup = (String) getGroup(groupPosition);

TextView textViewGroup = (TextView) convertView
.findViewById(R.id.group);
textViewGroup.setText(textGroup);

return convertView;
}

@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.item_layout, null);
}

TextView textViewItem = (TextView) convertView.findViewById(R.id.item);

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

textViewItem.setText(text);
return convertView;
}

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

}

最佳答案

发生错误是因为您从 fragment 启动它。使用

Hotel.this.getActivity().getApplicationContext()

像这样的一流酒店:

myExpandableListAdapter = new MyExpandableListAdapter(Hotel.this.getActivity().getApplicationContext(), groupList, childMap);

关于java - android studio ExpandableListAdapter 上下文错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32662976/

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