0

使用 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 返回的标题?

4

1 回答 1

7

您可以使用 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;
    }
于 2013-10-26T18:04:47.827 回答