android子和父列表

时间:2015-05-10 10:40:22

标签: android android-layout

是否可以使用列表视图以下面显示的格式在android中获取布局?

按照教程(http://www.androidbegin.com/tutorial/android-json-parse-images-and-texts-tutorial/),我能够获得正常的列表视图。

但无法获得如下所示的布局

Sample View

提前致谢。

1 个答案:

答案 0 :(得分:1)

ExpandableListView是一个很好的方法,如果你想要折叠/扩展你的listview项目,或者你可以使用多行适配器,如

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View mView = convertView;
    ViewHolder mHolder = null;
    ViewHeaderHolder mHeaderHolder = null;
    YourRowItem item = getItem(position);
    boolean isSection = item.isHeaderItem();
    if (mView == null) {
        if (isSection) {
            mHeaderHolder = new ViewHeaderHolder();
            mView = mInflater.inflate(R.layout.header_row, null);
            // initialise your view
            mView.setClickable(false);
            mView.setFocusable(false);
            mView.setOnClickListener(null);
            mView.setTag(mHeaderHolder);
        } else {
            mView = mInflater.inflate(R.layout.child_row, parent, false);
            mHolder = new ViewHolder();
            // initialise your view 
            mView.setTag(mHolder);
        }
    } else {
        if (isSection) {
            mHeaderHolder = (ViewHeaderHolder) mView.getTag();
        } else {
            mHolder = (ViewHolder) mView.getTag();
        }
    }

    if (!isSection) {
        // add values to child view
    } else {
        // add values to header view
    }
    return mView;
}

@Override
public int getViewTypeCount() {
    return 2;
}

@Override
public int getItemViewType(int position) {
    return ((YourRowItem) getItem(position)).isHeaderItem() ? 0 : 1;
}