Android-ExpandableListView不显示任何内容

凯文·默维(Kevin Murvie)

因此,我刚刚进入的领域,ExpandableListView并希望制作一个简单的列表,其中只有一个小组和三个孩子。DrawerLayout

这是我的适配器代码:

    public class DrawerShopAdapter extends BaseExpandableListAdapter {
    private Context context;
    private List<String> headerTitle = new ArrayList<>();
    private List<DrawerShopModel> drawerList = new ArrayList<>();

    public DrawerShopAdapter(Context context, List<DrawerShopModel> dataset) {
        this.context = context;
        this.drawerList.addAll(dataset);
        this.headerTitle.add("Toko Saya");
    }

    @Override
    public Object getChild(int groupPosition, int childPosititon) {
        return this.drawerList.get(childPosititon).drawer_txt;
    }

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

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

        final String childText = (String) getChild(groupPosition, childPosition);

        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this.context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.drawer_shop_item, null);
        }

        ImageView drawerIcon = (ImageView)convertView.findViewById(R.id.drawer_shop_item_img);
        OpenSansFont drawerTxt = (OpenSansFont) convertView.findViewById(R.id.drawer_shop_item_txt);

        drawerIcon.setImageDrawable(context.getResources().getDrawable(drawerList.get(childPosition).drawer_image));
        drawerTxt.setText(childText);
        return convertView;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return  this.drawerList.size();
    }

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

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

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

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

        OpenSansFont listHeader = (OpenSansFont) convertView
                .findViewById(R.id.drawer_shop_header_title);
//        listHeader.setTypeface(null, Typeface.BOLD);
        listHeader.setText(headerTitle);

        return convertView;
    }

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

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
}

这是我的 DrawerShopModel

public class DrawerShopModel {
    public int drawer_image;
    public String drawer_txt;

    @Override
    public String toString() {
        return drawer_txt;
    }
}

我只是遵循MultiAutocompleteTextView方法来制作模型。

最后,这是我在抽屉中的称呼方式:

public void setupShop(){
    expandableListView.setVisibility(View.VISIBLE);
    int images[] = { R.drawable.penjualan_gray, R.drawable.daftar_produk, R.drawable.keluhan_gray };
    String[] names = { "Penjualan", "Daftar Produk", "Keluhan"};

    List<DrawerShopModel> drawerShopModels = new ArrayList<>();

    for (int i = 0; i < 3; i++){
        DrawerShopModel drawerShopModel = new DrawerShopModel();
        drawerShopModel.drawer_image = images[i];
        drawerShopModel.drawer_txt = names[i];
        drawerShopModels.add(drawerShopModel);
    }

    drawerShopAdapter = new DrawerShopAdapter(this.getActivity(), drawerShopModels);
expandableListView.setAdapter(drawerShopAdapter);
}

该列表在抽屉中根本没有显示。我对适配器不满意,有人可以引导我朝着正确的方向发展吗?

阿迪亚·维阿斯·拉汉(Aditya vyas-lakhan)

如果您要获取抽屉式布局中的可扩展列表,请尝试这种方式,这正是您要寻找的

public class CustomExpandableListAdapter extends BaseExpandableListAdapter {

    private Context mContext;
    private List<String> mExpandableListTitle;
    private Map<String, List<String>> mExpandableListDetail;
    private LayoutInflater mLayoutInflater;

    public CustomExpandableListAdapter(Context context, List<String> expandableListTitle,
                                       Map<String, List<String>> expandableListDetail) {
        mContext = context;
        mExpandableListTitle = expandableListTitle;
        mExpandableListDetail = expandableListDetail;
        mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public Object getChild(int listPosition, int expandedListPosition) {
        return mExpandableListDetail.get(mExpandableListTitle.get(listPosition))
            .get(expandedListPosition);
    }

    @Override
    public long getChildId(int listPosition, int expandedListPosition) {
        return expandedListPosition;
    }

    @Override
    public View getChildView(int listPosition, final int expandedListPosition,
                             boolean isLastChild, View convertView, ViewGroup parent) {
        final String expandedListText = (String) getChild(listPosition, expandedListPosition);
        if (convertView == null) {
            convertView = mLayoutInflater.inflate(R.layout.list_item, null);
        }
        TextView expandedListTextView = (TextView) convertView
            .findViewById(R.id.expandedListItem);
        expandedListTextView.setText(expandedListText);
        return convertView;
    }

    @Override
    public int getChildrenCount(int listPosition) {
        return mExpandableListDetail.get(mExpandableListTitle.get(listPosition))
            .size();
    }

    @Override
    public Object getGroup(int listPosition) {
        return mExpandableListTitle.get(listPosition);
    }

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

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

    @Override
    public View getGroupView(int listPosition, boolean isExpanded,
                             View convertView, ViewGroup parent) {
        String listTitle = (String) getGroup(listPosition);
        if (convertView == null) {
            convertView = mLayoutInflater.inflate(R.layout.list_group, null);
        }
        TextView listTitleTextView = (TextView) convertView
            .findViewById(R.id.listTitle);
        listTitleTextView.setTypeface(null, Typeface.BOLD);
        listTitleTextView.setText(listTitle);
        return convertView;
    }

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

    @Override
    public boolean isChildSelectable(int listPosition, int expandedListPosition) {
        return true;
    }
}

有关更多信息,请检查抽屉中的可扩展列表

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Android Listview不显示任何内容

来自分类Dev

Android Studio Logcat不显示任何内容

来自分类Dev

带有ArrayAdapter的Android ListView不显示任何内容

来自分类Dev

Android Wifi Direct onPeersAvailable不显示任何内容

来自分类Dev

更改方向时,Android Listview 不显示任何内容

来自分类Dev

从 Android Studio 的 Palette 中拖放任何内容时不显示任何内容

来自分类Dev

Android CardView不显示内容

来自分类Dev

Android ListView不显示内容

来自分类Dev

Android-使用BaseAdapter的自定义列表视图不显示任何内容

来自分类Dev

Android:TabLayout不显示任何标签

来自分类Dev

Android:Eclipse不显示任何视图属性

来自分类Dev

Android:Listview不显示任何结果

来自分类Dev

Android Studio ClipArt不显示任何图标

来自分类Dev

内容在Android 4.1.1中不显示

来自分类Dev

android选项卡内容不显示

来自分类Dev

Android ViewPager不显示内容图像

来自分类Dev

通知不显示,但不会引发任何错误[Android]

来自分类Dev

ViewPager不显示任何内容

来自分类Dev

NSFetchRequest不显示任何内容

来自分类Dev

LinearLayout不显示任何内容

来自分类Dev

Webview 不显示任何内容

来自分类Dev

凌空android不显示来自json的数据而不显示任何错误

来自分类Dev

android在viewholder中设置了widget的大小,但是内容不显示?

来自分类Dev

显示数据不显示任何内容

来自分类Dev

Android的标签视图中未显示任何内容

来自分类Dev

Android版Google Analytics(分析)未显示任何内容

来自分类Dev

Android的标签视图中未显示任何内容

来自分类Dev

Android应用程序未显示任何内容

来自分类Dev

Android版Google Analytics(分析)未显示任何内容

Related 相关文章

热门标签

归档