Android线性布局不可见

时间:2016-08-12 08:10:57

标签: java android xml android-layout android-linearlayout

我有一个问题,我想在检查条件后在父级中显示线性布局。我想在父布局的主体中显示线性布局android:id="@+id/linearIndex"。这是代码。

  

布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="gone"
    android:id="@+id/lstep3">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:visibility="gone"
    android:id="@+id/linearIndex"> //THE LAYOUT I WANT TO SHOW
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:textStyle="bold"
        android:text="Jumlah Kasus Tambahan di Lokasi PE"
        android:textColor="@color/teal"
        />
    <!-- daftar gejala yang dimasukkan-->
    <ListView
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:id="@+id/listvievadvance2"
        android:layout_marginTop="10dp"></ListView>

    <!-- form gejala-->
    <!-- form data gejala-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="5dp"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="15dp"
        android:background="@color/accent_501">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Pilih Lokasi"
            android:textStyle="bold"/>
        <Spinner
            android:id="@+id/lokasiPilih"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="7dp"
            />

        <TextView
            android:id="@+id/txtLocLain"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Lokasi lain"
            android:textStyle="bold"
            />
        <EditText
            android:layout_width="match_parent"
            android:layout_marginTop="7dp"
            android:hint="Lokasi lain"
            android:layout_height="wrap_content"
            android:id="@+id/lokasiLain"
            android:theme="@style/TextLabel"
            />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Tanggal PE"
            android:textStyle="bold"
            />
        <EditText
            android:layout_width="match_parent"
            android:layout_marginTop="7dp"
            android:hint="Tanggal PE"
            android:layout_height="wrap_content"
            android:id="@+id/tglPE"
            android:editable="false"
            android:theme="@style/TextLabel"
            />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Jumlah Kasus tambahan"
            android:textStyle="bold"
            />
        <EditText
            android:layout_width="match_parent"
            android:layout_marginTop="7dp"
            android:hint="Masukan jumlah kasus"
            android:layout_height="wrap_content"
            android:id="@+id/jmlKasusTambah"
            android:theme="@style/TextLabel"
            />

        <Button
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:id="@+id/btambahLokasi"
            android:text="Tambah"
            android:textColor="#fff"
            android:layout_marginTop="10dp"
            android:background="@color/teal"
            />

    </LinearLayout>
</LinearLayout>

和java文件

  

显示布局可见性的功能

 private void checkIndexOrNot(){

    Log.i("Value :", String.valueOf(campak.getSurveilans().getStatusKasus()));

    if(Integer.parseInt(campak.getSurveilans().getStatusKasus()) == 1) {
        linearIndex.setVisibility(View.VISIBLE);
    } else {
        linearIndex.setVisibility(View.GONE);
    }

}

我知道它看起来没问题,但显示布局可见性的功能不起作用。检查条件后,布局不显示。从DB检查的条件的逻辑工作正常,没有错误。 我将checkIndexOrNot()放在onCreate()函数中。

提前谢谢。

2 个答案:

答案 0 :(得分:1)

您的linearIndex的父布局具有gone作为默认属性意味着它将不可见。要显示子视图,父布局必须可见。因此,要么将两个布局设置为以编程方式显示,要么只删除visibility="gone"中的lstep3

答案 1 :(得分:1)

只需从根布局中删除.subscribe

改变这个:

onError

对此:

android:visibility="gone"
相关问题