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?
--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to