【问题标题】:How to have the ITEM and SUBITEM in the list view如何在列表视图中有 ITEM 和 SUBITEM
【发布时间】:2013-10-26 17:50:29
【问题描述】:

使用 Android Studio,我在 MainActivity 中有这个 ListView

ArrayAdapter<RSSItem> adapter;
                adapter = new ArrayAdapter<RSSItem>(this,
                        android.R.layout.simple_list_item_1,myRssFeed.getList());

                setListAdapter(adapter);

这显示了我从 RSSItem 返回的提要的标题。 有没有办法获得描述,图像,ecc。 SUBITEM 和我为 ITEM 返回的标题?

【问题讨论】:

    标签: android listview


    【解决方案1】:

    您可以使用 Expendable 列表来显示组和子组的种类。为此,您需要创建一个 BaseExpandableListAdapter。你需要重写这个类的两个方法。

    @Override
        public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
             if (convertView == null) {
                    LayoutInflater inflater =  (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    convertView = inflater.inflate(R.layout.group_row, null);
                   }
            //TextView tv=new TextView(context);
             TextView tv = (TextView) convertView.findViewById(R.id.tvGroupName);
            //tv.setText(parentList[groupPosition]);
             tv.setText(category_list.get(groupPosition).toString());
            //tv.setPadding(70,0,0,10);
            //return tv;
             return convertView;
    
        }
    
    @Override
        public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
             if (convertView == null) {
                    LayoutInflater inflater =  (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    convertView = inflater.inflate(R.layout.child_row, null);
                   }
            //TextView tv=new TextView(context);
             TextView tv = (TextView) convertView.findViewById(R.id.tvPlayerName);
    
            //tv.setText(childList[groupPosition][childPosition]);
             tv.setText((String)((ArrayList)sub_category_list.get(groupPosition)).get(childPosition));
    
            //tv.setPadding(70,0,0,10);
            //return tv;
            return convertView;
        }
    

    【讨论】:

    • 感谢您的回答,但是有没有办法让一个简单的列表视图包含项目和子项目?
    • 没有。你只需要去定制。
    • 你确定只有定制吗?我在我的设备上使用 Google Play,我可以看到一个包含许多项目的简单 ListView。
    • 不,好的,我明白该怎么做了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-22
    • 1970-01-01
    • 1970-01-01
    • 2019-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多