图像不显示在expandablelistview上

bhmjp9jg  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(202)

我正在制作一个可扩展的列表视图,以图像作为项目。显示标题,但不显示项目(图像)。我按了列表,但没有错误信息。如何解决?代码如下:
expandableimageitemsadapter.java(适配器)

public class ExpandableImageItemsAdapter extends BaseExpandableListAdapter {
    private final Context context;
    private final List<String> listDataHeader;
    private final HashMap<String,Integer> listHashMap;

    public ExpandableImageItemsAdapter(Context context, List<String> listDataHeader, HashMap<String,Integer> listHashMap) {
        this.context = context;
        this.listDataHeader = listDataHeader;
        this.listHashMap = listHashMap;
    }

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

    @Override
    public int getChildrenCount(int i) {
        List<Integer> list = Collections.singletonList(listHashMap.get(i));
        if (list == null) return 0;
        return list.size();
    }

    @Override
    public Object getGroup(int i) {
        return listDataHeader.get(i);
    }

    @Override
    public Object getChild(int i, int i1) {
        return Objects.requireNonNull(listHashMap.get(listDataHeader.get(i)));
    }

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

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

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

    @SuppressLint("InflateParams")
    @Override
    public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
        String headerTitle = (String)getGroup(i);
        if(view == null)
        {
            LayoutInflater inflater = (LayoutInflater)this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.chapter_list,null);
        }
        android.widget.TextView lblListHeader = (android.widget.TextView)view.findViewById(R.id.chaptertv);
        lblListHeader.setTypeface(null, Typeface.BOLD);
        lblListHeader.setText(headerTitle);
        return view;
    }

    @SuppressLint("InflateParams")
    @Override
    public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {

        if(view == null)
        {
            LayoutInflater inflater = (LayoutInflater)this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.topic_image_items,null);
        }

        ImageView imageitem = view.findViewById(R.id.imageitem);

        return view;
    }

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

主题\图像\项目.xml(项目)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/imageitem"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="24dp"
        tools:ignore="ContentDescription" />
</LinearLayout>

subf\u gitar\u kuncigitar.xml(列表)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="match_parent"
    tools:context=".mainfrag.kuncigitar">
    <ExpandableListView
        android:id="@+id/kuncigitarlist"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_height="match_parent"
        android:layout_width="match_parent">
    </ExpandableListView>

</RelativeLayout>

kuncigitar.java(列表,java)

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.subf_gitar_kuncigitar, container, false);
        kuncigitarlist = view.findViewById(R.id.kuncigitarlist);
        judul=new ArrayList<>();
        judul.add("Testing");
        isi = new HashMap<>();
        isi.put("picture1", R.drawable.guitar_parts);
        adapter = new ExpandableImageItemsAdapter(getContext(), judul, isi);
        kuncigitarlist.setAdapter(adapter);
        return view;
    }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题