ok,benutzerdefinierte Ansicht mit Layout
was ich versuche, eine benutzerdefinierte Ansicht in das Standard-Layout main.xml zu tun ist, einzubetten:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.lam.customview.CustomDisplayView
android:id="@+id/custom_display_view1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/prev"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="50"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/prev" />
</LinearLayout>
</LinearLayout>
, wie Sie die Klasse com genannt zu sehen ist. lam.customview.CustomDisplayView mit der ID custom_display_view1.
jetzt in der com.lam.customview.CustomDisplayView Klasse, ich möchte ein anderes Layout namens custom_display_view.xml verwenden, weil ich nicht programmgesteuert Steuerelemente/Widgets erstellen möchte.
custom_display_view.xml ist nur eine Taste und ein Bild, dessen Inhalt ich auf Grundlage bestimmter Bedingungen ändern wollen:
1)
public CustomDisplayView(Context context, AttributeSet attrs) {
super(context, attrs);
try
{
// register our interest in hearing about changes to our surface
SurfaceHolder holder = getHolder();
holder.addCallback(this);
View.inflate(context, R.layout.custom_display_view, null);
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/display_text_view1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<ImageView
android:id="@+id/display_image_view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
</LinearLayout>
ich zu tun versucht
...
, aber habe diesen Fehler, "03-08 20: 33: 15.711: Fehler/onCreate (10879): Binär XML-Datei Zeile # 8: Fehler beim Aufblasen der Klasse java.lang.reflect.Constructor ".
2)
public CustomDisplayView(Context context, AttributeSet attrs) {
super(context, attrs);
try
{
// register our interest in hearing about changes to our surface
SurfaceHolder holder = getHolder();
holder.addCallback(this);
View.inflate(context, R.id.custom_display_view1, null);
...
aber habe diesen Fehler, „03-08 20: 28: 47,401: ERROR/CustomDisplayView (10806): Ressourcen ID # 0x7f050002 Typ # 0x12 ist nicht gültig "
auch, wenn ich es auf diese Weise zu tun, wie jemand vorgeschlagen hat, es mir nicht klar ist, wie th e custom_display_view.xml ist der benutzerdefinierten Ansichtsklasse zugeordnet.
danke.
Sprache? Rahmen? –
hi ich habe das gleiche Problem ... hast du irgendeine Lösung ??? – Ads