如何更改活动中的布局文件?

时间:2017-12-29 11:22:14

标签: java android android-layout

我想在expandabl列表视图适配器中更改XML文件。但是没有OnCreate方法。我用OnCreate方法看了几个Code示例。但有没有办法在没有它的情况下做到这一点?我想把它放在我的getGroupView方法上。在if问题中。

抱歉,我是Android Studio的新手:/我需要一点时间来理解所有的事情:)

@Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        ExpandedMenuModel headerTitle = (ExpandedMenuModel) getGroup(groupPosition);
        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this.mContext
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.listheader, null);
        }
        TextView lblListHeader = (TextView) convertView
                .findViewById(R.id.submenu);

        lblListHeader.setTypeface(null, Typeface.BOLD);
        lblListHeader.setText(headerTitle.getIconName());

        if ( getChildrenCount( groupPosition ) == 0 ) {
             //HERE I WANT TO PUT IT IN
        } else {
            //HERE I WANT TO PUT IT IN
        }
        return convertView;
    }

layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    xmlns:tools="http://schemas.android.com/tools">

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        android:backgroundTint="@color/colorPrimary">

        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="@mipmap/ic_launcher_round"
            android:layout_marginTop="100dp"
            android:layout_gravity="center_horizontal"
            />

        <ExpandableListView
            android:id="@+id/navigationmenu"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="220dp"
            android:groupIndicator="@android:color/transparent"
            android:background="@android:color/white">
        </ExpandableListView>


        <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <View android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="?android:attr/listDivider"/>

        </FrameLayout>

    </android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

enter image description here

0 个答案:

没有答案