【发布时间】:2016-08-12 08:10:56
【问题描述】:
我有一个问题,我想在检查条件后在父级中显示线性布局。我想在父布局的正文中显示线性布局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);
}
}
我知道它看起来没有问题,但是显示布局可见性的功能不起作用。检查条件后布局不显示。从数据库检查的条件逻辑工作正常,没有错误。 我将 checkIndexOrNot() 放在 onCreate() 函数中。
提前谢谢你。
【问题讨论】:
-
因为 id
lstep3的根LinearLayout总是消失了。删除lstep3中的android:visibility="gone",你会看到你的LinearLayout -
是的,就是这样。它的父级是
gone,所以只需删除它。你,伙计,应该写下答案并让其接受@PhanVanLinh。 -
非常感谢,我接受你的回答@PhanVanLinh
标签: java android xml android-layout android-linearlayout