res/layout/bughunt.xml is a basic definition of a custom view; it's just a layout with a single EditText inside.
Using xml Syntax Highlighting
- <?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>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4
My custom view class:
Using java Syntax Highlighting
- 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);
- }
- }
Parsed in 0.012 seconds, using GeSHi 1.0.8.4
Then I put two instances like the following in an Activity layout file:
Using xml Syntax Highlighting
- <my.package.BugHunt
- layout_width="wrap_content"
- layout_height="wrap_content" />
Parsed in 0.000 seconds, using GeSHi 1.0.8.4
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?