Question

I am attempting to achieve a result similar to:

http://cdn7.staztic.com/app/a/2541/2541494/share-my-contact-unlocker-2-0-s-307x512.jpg

Where contacts might or might not have email addresses or other profile information. Is it possible to achieve the majority of it through XML or does it all need to be done through Java?

Here is the pseudocode that I imagine would be a solution:

if (contact.hasPhoneNumber)

foreach number in contact

inflate r.layout.contact_number

settext phonenumber textview

add view to layout

Is there a smarter approach?

Was it helpful?

Solution

This was solved by having the following:

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/contactContent"
    android:layout_below="@+id/profile_background">
    <LinearLayout android:orientation="vertical" android:id="@+id/c_detail_content_main" android:paddingBottom="50.0dip" android:layout_width="fill_parent" android:layout_height="wrap_content">
        <LinearLayout android:orientation="vertical" android:visibility="gone"  android:id="@+id/c_detail_birthday_layout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="20.0dip">
</LinearLayout
</ScrollView>

And the following code:

if (this.contact.hasPhoneNumber())
    {
        LinearLayout phoneNumberContent = (LinearLayout) view.findViewById(R.id.c_detail_phone_layout);
        phoneNumberContent.setVisibility(View.VISIBLE);
        for (PhoneNumber number : this.contact.getPhoneNumbers())
        {
            LinearLayout tempNumberContent = new LinearLayout(this.getActivity().getApplicationContext());
            TextView type = new TextView(this.getActivity().getApplicationContext());
            TextView phoneNo = new TextView(this.getActivity().getApplicationContext());
            type.setWidth(LayoutTools.getDPMeasurement(this.getActivity(), 85));
            phoneNo.setText(number.getNumber());
            tempNumberContent.addView(type);
            tempNumberContent.addView(phoneNo);
            phoneNumberContent.addView(tempNumberContent);
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top