如何在列表视图中使用ITEM和SUBITEM

时间:2013-10-26 17:50:29

标签: android listview

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

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

                setListAdapter(adapter);

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

1 个答案:

答案 0 :(得分:7)

您可以使用“可消耗”列表,该列表允许您显示组和子组的类型。为此,您需要创建一个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;
    }
相关问题