I am looking for a way to override my own XML view in android.
So I only have to specify settings (like background, border, default content) once – and use it again.
The problem is that I can’t find anything about it.
(The things I found are about using a java class in XML to override, this is not what I want)
This is some non-working code, but I hope it explains it well enough to you:
main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<field android:text="@string/str1" />
<field android:text="@string/str2" />
<field android:text="@string/str3" />
<field android:text="@string/str4" />
<field android:text="@string/str5" />
</LinearLayout>
code representing field (field.xml):
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/field"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@layout/field_background"
android:text="@string/default_string"/>
As you see field itself is once defined and used many times with one customization. (Another string as text set)
This doesn’t work at all, but I hope someone knows a way to make something like this work. (Without coding, just XML)
Thanks,
Dennis
I’d suggest that you set up a style. In some file (usually
styles.xml) inres/values, add a style for your field:Then in
main.xml:I just copied your values, but it’s wrong to have the same
android:idvalue for several views in a layout and it’s weird to have a layout as a background.