On Sep 28, 1:15 am, Romain Guy <[email protected]> wrote:
> Your two views have the same id, so yes, they try to share the same
> state. You will need to somehow generate their id to make them unique
> (Home does that.)

Okay, thanks! I wasn't sure how the SavedState object was being
referenced. If it's by ID I have some ideas of how to fix this. I
started a thread on anddev (http://www.anddev.org/viewtopic.php?
p=27310) and I'll post my workaround there when I write it.

Ben

> On Sun, Sep 27, 2009 at 10:02 PM, Ben Roberts <[email protected]> wrote:
>
> > I'm trying to figure out how to properly make a custom view consisting
> > of a LinearLayout and some children, one of which is a EditText. To
> > make this simple, I've pared down the code to the simplest possible
> > case.
>
> > res/layout/bughunt.xml is a basic definition of a custom view; it's
> > just a layout with a single EditText inside.
> > <?xml version="1.0" encoding="utf-8"?>
> > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
> > android"
> >        android:orientation="horizontal"
> >        android:gravity="center_vertical"
> >        android:layout_width="wrap_content"
> >        android:layout_height="wrap_content">
> >        <EditText
> >                android:id="@+id/text1"
> >                android:layout_width="wrap_content"
> >                android:layout_height="40sp"
> >                android:gravity="center"
> >                android:width="50sp"
> >                android:singleLine="true"/>
> > </LinearLayout>
>
> > My custom view class:
>
> > public class BugHunt extends LinearLayout {
>
> >        public BugHunt(Context context) {
> >                super(context);
> >                initLayout(context);
> >        }
>
> >        public BugHunt(Context context, AttributeSet attrs) {
> >                super(context, attrs);
> >                initLayout(context);
> >        }
>
> >        private void initLayout(Context context) {
> >                LayoutInflater i = (LayoutInflater) context.getSystemService
> > (Context.LAYOUT_INFLATER_SERVICE);
> >                i.inflate(R.layout.bughunt, this);
> >        }
> > }
>
> > Then I put two instances like the following in an Activity layout
> > file:
> > <my.package.BugHunt
> >        layout_width="wrap_content"
> >        layout_height="wrap_content" />
>
> > The problem I'm having is when the EditTexts save state, they
> > overwrite each other's state. To reproduce this, put two or more
> > instances of BugHunt into an Activity, run it, and enter some
> > (different) text into each EditText. Then, switch the screen
> > orientation. After the layout is redrawn, all EditTexts will have the
> > same text in them (the text from whichever EditText saved state last).
>
> > I can only guess that I'm not using the LayoutInflater properly. Any
> > ideas?
>
> --
> Romain Guy
> Android framework engineer
> [email protected]
>
> Note: please don't send private questions to me, as I don't have time
> to provide private support.  All such questions should be posted on
> public forums, where I and others can see and answer them
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to