削除可能な を作成しましたEditText
。レイアウトはこちら
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" >
<EditText
android:id="@+id/cacEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:paddingRight="35dp" />
<Button
android:id="@+id/cacClearButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:background="@android:drawable/ic_input_delete"
android:visibility="invisible" />
</RelativeLayout>
問題は、これらを 1 つのレイアウトにさらに配置して横向きに回転すると、すべてが突然同じ値になることです。システムがIDで値を復元し、各コンポーネントが同じIDの要素で構成されているためだと思います。どうすればこの問題を解決できますか?
より詳しい情報:
削除可能EditText
( cz.kns.uome.component.CleanAndClearEditText
) レイアウトで
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/cz.kns.uome"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<cz.kns.uome.component.CleanAndClearEditText
android:id="@+id/nameEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/contactPickerButton"
app:hint="@string/person_name"
app:type="textPersonName" />
<ImageButton
android:id="@+id/contactPickerButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:contentDescription="@string/select_contact"
android:src="@drawable/ic_action_dropdown" />
</RelativeLayout>
<cz.kns.uome.component.CleanAndClearEditText
android:id="@+id/emailEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:hint="@string/person_email_opt"
app:type="textEmailAddress" />
<cz.kns.uome.component.CleanAndClearEditText
android:id="@+id/descriptionEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:hint="@string/description_opt"
app:type="text" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/saveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5"
android:text="@string/save" />
<Button
android:id="@+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="@string/cancel" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Java クラス
public class CleanAndClearEditText extends RelativeLayout {
private final EditText editText;
private final Button clearButton;
public CleanAndClearEditText(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.clean_and_clear_edit_text, this);
TypedArray typedArray = getContext().obtainStyledAttributes(attrs,
R.styleable.ClearAndCleanEditText);
// ?????
// I have to somehow access that edittext here but static id does not work
editText = (EditText) findViewById(R.id.cacEditText);
editText.addTextChangedListener(textWatcher);
editText.setHint(typedArray.getString(R.styleable.ClearAndCleanEditText_hint));
String type = typedArray.getString(R.styleable.ClearAndCleanEditText_type);
if (type != null) {
editText.setInputType(InputTypes.get(type));
}
clearButton = (Button) findViewById(R.id.cacClearButton);
clearButton.setOnClickListener(clearButtonListener);
}
// rest ommited
}