Reputation: 3339
I have a TextView
and an Image
within my LinearLayout
if a phone value gets passed through to the activity through an intent, then I set the visibility of the layout that contains the text and image to visible.
In my code the layout shows up, but the text and image don't even though they are set to visible in the same check that makes the layout visible. I've added my xml and the Java code that sets visibility in my code.
if(extras.getString("phone") != null){
Log.d("PHONE VISIBLE", "phone made clayout visible");
contactsLayout.setVisibility(View.VISIBLE);
phoneLayout.setVisibility(View.VISIBLE);
mPhone = extras.getString("phone");
Log.d("places got phone", mPhone.toString());
phone.setText(mPhone);
}
Here's my xml code
<LinearLayout
android:id="@+id/contactsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_below="@+id/summary"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/contactsLabel"
android:background="@color/gray"
android:paddingLeft="16dp"
android:text="contact"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/phoneLayout"
android:orientation="horizontal"
android:visibility="gone">
<ImageView
android:id="@+id/phoneImage"
android:src="@drawable/icon_phone"
android:layout_width="60dp"
android:layout_height="60dp"/>
<TextView
android:id="@+id/phoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
tools:text="phoneNumber"/>
</LinearLayout>
<LinearLayout
android:id="@+id/emailLayout"
android:paddingLeft="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:id="@+id/emailImage"
android:src="@drawable/icon_email"
android:layout_width="60dp"
android:layout_height="60dp" />
<TextView
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
tools:text="email"/>
</LinearLayout>
</LinearLayout>
Upvotes: 1
Views: 2888
Reputation:
replace your xml with
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/contactsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_below="@+id/summary"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/contactsLabel"
android:background="#F4F3F3"
android:paddingLeft="16dp"
android:text="contact"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/phoneLayout"
android:orientation="horizontal"
android:visibility="gone">
<ImageView
android:id="@+id/phoneImage"
android:src="@drawable/ic_launcher"
android:layout_width="60dp"
android:layout_height="60dp"/>
<TextView
android:id="@+id/phoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
tools:text="phoneNumber"/>
</LinearLayout>
<LinearLayout
android:id="@+id/emailLayout"
android:paddingLeft="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:id="@+id/emailImage"
android:src="@drawable/ic_launcher"
android:layout_width="60dp"
android:layout_height="60dp" />
<TextView
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
tools:text="email"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Make sure your "phone" container in which you have set phone is visible
if(getIntent().getExtras() != null)
{
contactsLayout.setVisibility(View.VISIBLE);
phoneLayout.setVisibility(View.VISIBLE);
mPhone = extras.getString("phone");
phone.setText(mPhone);
}
Upvotes: 0
Reputation: 68
Change your contactsLayout orientation to vertical then you can able to see the phonelayout.
Upvotes: 0
Reputation: 461
As Mike said
Change contactsLabel as follows:
TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/contactsLabel"
android:background="@color/gray"
android:paddingLeft="16dp"
android:text="contact"/>
Upvotes: 1