嵌套的可扩展列表视图编辑文本折叠列表视图

时间:2015-09-14 23:06:07

标签: android xml expandablelistview

大家好我已经构建了这个嵌套的可扩展列表,一切正常,除非编辑文本被聚焦,整个列表都会被折叠。提供者和xml视图的代码。我在这里缺少什么?

外部列表

public class DashboardDrawerExpandableListAdapter extends BaseExpandableListAdapter {

    Context mAdapterContext;
    private List<String> _listDataHeader; // header titles
    private HashMap<String, List<String>> _listDataChild;
    private ExpandableListView mParent;

    List<String> listDataHeader;
    HashMap<String, List<String>> listDataChild;


    public DashboardDrawerExpandableListAdapter(Context context, List<String> listDataHeader, HashMap<String, List<String>> listChildData, ExpandableListView parent) {
        this.mAdapterContext = context;
        this._listDataHeader = listDataHeader;
        this._listDataChild = listChildData;
        this.mParent = parent;
    }

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

    @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) mAdapterContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.dashboard_drawer_inner_expandable_list_header, null);
        }

        prepareInnerListData();

        ExpandableListView innerExpandableList =(ExpandableListView) convertView.findViewById(R.id.inner_expandable_list);
        DashboardDrawerExpandableInnerListAdapter drawerexpandableadapter = new DashboardDrawerExpandableInnerListAdapter(mAdapterContext, listDataHeader, listDataChild,innerExpandableList);
        innerExpandableList.setAdapter(drawerexpandableadapter);

        return convertView;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return this._listDataChild.get(this._listDataHeader.get(groupPosition)).size();
    }

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

    @Override
    public int getGroupCount() {
        return this._listDataHeader.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) mAdapterContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.dashboard_drawer_expandable_list_header_item, null); // main greyed header
            TextView groupHeader = (TextView) convertView.findViewById(R.id.groupHeaderText);
            groupHeader.setTypeface(null, Typeface.BOLD);
            groupHeader.setText(headerTitle);
        }
        return convertView;
    }

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

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

    private void prepareInnerListData() {
        listDataHeader = new ArrayList<String>();
        listDataChild = new HashMap<String, List<String>>();

        // Adding child data
        listDataHeader.add("Date Range");
        listDataHeader.add("Location(s)");

        // Adding child data
        List<String> filteritems = new ArrayList<String>();
        filteritems.add(" ");

        listDataChild.put(listDataHeader.get(0), filteritems);
        listDataChild.put(listDataHeader.get(1), filteritems);
    }
}

内部列表

public class DashboardDrawerExpandableInnerListAdapter extends BaseExpandableListAdapter {
    Context mAdapterContext;
    private List<String> _listDataHeader; // header titles
    private HashMap<String, List<String>> _listDataChild;
    private ExpandableListView mParent;

    public DashboardDrawerExpandableInnerListAdapter(Context context, List<String> listDataHeader, HashMap<String, List<String>> listChildData, ExpandableListView parent) {
        this.mAdapterContext = context;
        this._listDataHeader = listDataHeader;
        this._listDataChild = listChildData;
        this.mParent = parent;
    }

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

    @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) mAdapterContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            switch (groupPosition){
                case 0:
                    convertView = infalInflater.inflate(R.layout.expandable_list_item_date_range, null);
                    break;
                case 1:
                    convertView = infalInflater.inflate(R.layout.expandable_list_item_locations, null);
                    break;
                default:
                    break;
            }
        }
        return convertView;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return this._listDataChild.get(this._listDataHeader.get(groupPosition)).size();
    }

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

    @Override
    public int getGroupCount() {
        return this._listDataHeader.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) mAdapterContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            switch (groupPosition){
                case 0:
                    convertView = infalInflater.inflate(R.layout.expandable_list_header_date_range, null);
                    break;
                case 1:
                    convertView = infalInflater.inflate(R.layout.expandable_list_header_location, null);
                    break;
                default:
                    break;
            }
        }

        TextView groupHeader = (TextView) convertView.findViewById(R.id.inner_group_header_text);
        groupHeader.setTypeface(null, Typeface.BOLD);
        groupHeader.setText(headerTitle);

        return convertView;
    }

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

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

外部列表xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:background="#616161"
    android:layout_height="wrap_content">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:padding="10dp">

        <TextView
            android:layout_width="0dp"
            android:layout_weight=".5"
            android:layout_height="wrap_content"
            android:id="@+id/groupHeaderText"
            android:textSize="18sp"
            android:layout_gravity="center" />

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="Reset"
            android:id="@+id/button2"
            android:focusable="false"
            android:layout_weight=".5"
            android:layout_gravity="center" />
    </LinearLayout>

</RelativeLayout>

内部列表xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ExpandableListView
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:isScrollContainer="false"
        android:id="@+id/inner_expandable_list" />

</LinearLayout>

0 个答案:

没有答案