Wednesday, December 16, 2009

[android-developers] Re: Using Adapters

Okay, so I've got down the LinearLayout in a ScrollView way and I seem
to have hacked something together... But, it doesn't quite work.

It does something - see the linked pictures

Hierarchy:
Before http://tinyurl.com/ybl7f8j
After http://tinyurl.com/ybohtyv

App:
Before http://tinyurl.com/yblw2mp
After http://tinyurl.com/ycjfoya

As you can see, it seems to add it but not display it. Clicking on my
add button adds as many as I want according the hierarchy viewer, but
the buttons only move to accommodate them once.

It was guess work that got me this far, so I'm not entirely sure if
I'm using methods correctly here. But the main xml layout is:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/edit_options"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="@string/edit_offer1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical" />
<EditText
android:id="@+id/product_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName" />
</LinearLayout>
<View
android:background="@android:drawable/divider_horizontal_bright"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip">
<TextView
android:text="@string/edit_subtitle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical" />
<ImageButton
android:id="@+id/add_attr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_add_states">
</ImageButton>
</LinearLayout>
<LinearLayout
android:id="@+id/attr_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/attr_row_default"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:hint="Attribute"
android:layout_width="0dip"
android:layout_weight="2"
android:layout_height="wrap_content"
android:inputType="textPersonName" />
<EditText
android:hint="Value"
android:layout_width="0dip"
android:layout_weight="3"
android:layout_height="wrap_content"
android:inputType="textPersonName" />
<ImageButton
android:id="@+id/drop_attr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_delete_states"
android:layout_gravity="center_vertical" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
<Button
android:id="@+id/btn_done"
android:text="@string/ok"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/btn_discard"
android:text="@string/discard"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>

</ScrollView>

Each extra row has the following xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/attr_row"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:hint="Attribute"
android:layout_width="0dip"
android:layout_weight="2"
android:layout_height="wrap_content"
android:inputType="textPersonName" />
<EditText
android:hint="Value"
android:layout_width="0dip"
android:layout_weight="3"
android:layout_height="wrap_content"
android:inputType="textPersonName" />
<ImageButton
android:id="@+id/drop_attr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_delete_states"
android:layout_gravity="center_vertical" />
</LinearLayout>

The code tied to the imageButton with a Listener is

LinearLayout attrList = (LinearLayout) findViewById(R.id.attr_list);
LinearLayout extraAttr = (LinearLayout) LinearLayout.inflate
(v.getContext(),
R.layout.attr_row,
null);
attrList.addView(extraAttr);


In particular, I'm guessing I'm not using inflate correctly..

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate