Unerwartete Besetzung zu textview; layout-tag war relative layout
Ich bin neu in Android-Programmierung, und ich bin mit einem wirklich grundlegende problem, dass ich nicht herausfinden können. Ich versuche, ein Sudoku-app mit einer Reihe von Relativen Layouts. Aber wenn ich versuche, den text zu ändern in einer der TextViews in meiner app, ich bekomme diese Fehlermeldung:
Unerwartete Besetzung zu textview; layout-tag war relative layout
Jede Hilfe wäre hier sehr willkommen!
Dies ist der java-code, der den Fehler erzeugt:
private void message (){
TextView targetTextView = (TextView) findViewById(R.id.TL_Top_Left_Box);
targetTextView.setText("1");
}
Dies ist die zugrunde liegende XML (ziemlich gekürzt, weil der vollständige code ist sehr repetitiv):
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"
tools:context="com.example.android.sudoku.MainActivity">
<RelativeLayout
android:id="@+id/Sudoku_Grid"
android:layout_width="240dp"
android:layout_height="240dp"
android:background="@android:color/black"
android:layout_centerHorizontal="true">
<RelativeLayout
android:id="@+id/Top_Left_Grid"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="@android:color/black"
android:layout_toLeftOf="@id/Top_Center_Grid">
<RelativeLayout
android:id="@+id/TL_Top_Center_Box"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="@android:color/black"
android:background="@android:color/white"
android:layout_marginTop="1dp"
android:layout_marginRight="1dp"
android:layout_marginBottom="1dp"
android:layout_marginLeft="1dp"
android:textSize="17sp"
android:gravity="center"
android:text="0"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/TL_Top_Left_Box"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_toLeftOf="@id/TL_Top_Center_Box"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="@android:color/black"
android:background="@android:color/white"
android:layout_marginTop="1dp"
android:layout_marginRight="1dp"
android:layout_marginBottom="1dp"
android:textSize="17sp"
android:gravity="center"
android:text="0"/>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
<Button
android:id="@+id/Up_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/Sudoku_Grid"
android:layout_marginTop="25dp"
android:layout_centerHorizontal="true"
android:textSize="20sp"
android:onClick="Click_1"
android:text="Up"/>
</RelativeLayout>
- wählen Sie die id des relative layout statt der text-Ansicht. zuweisen von id zu textview und verwenden Sie die id in die message-Funktion
- Genau das richtige, vielen Dank! Antwort war so offensichtlich.
Du musst angemeldet sein, um einen Kommentar abzugeben.
Dies ist, wo die id
TL_Top_Left_Box
definiert ist:Werden Sie wahrscheinlich wollen, zu entfernen, die id-Zeile und fügen Sie Sie der
TextView
enthalten, dieRelativeLayout
statt:Du bist ersuchenden view mit der id TL_Top_Left_Box und Gießen es zu TextView. In das layout der Ansicht, die id ist ein RelativeLayout. Sie können nicht werfen ein RelativeLayout zu TextView.
Wenn Sie erwarten, wurden um eine TextView, dann verlangen Sie die korrekte id. Aber wenn Sie erwarten, wurden ein RelativeLayout, dann erstellen Sie eine variable mit diesem Typ statt und warf es mit diesem Typ.
RelativeLayout ist nicht TextView