Innerhalb einer CardView
Ich habe eine LinearLayout
mit drei TextViews
drin und ich möchte den Text von diesen TextViews bekommen. Meine XML-Datei sieht wie folgt aus:Wie bekomme ich Text von TextView in einem CardView?
<LinearLayout
android:id="@+id/defense"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
>
<android.support.v7.widget.CardView
android:id="@+id/cardCB"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
app:cardBackgroundColor="@android:color/transparent"
app:cardElevation="0dp">
<LinearLayout
android:id="@+id/innerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Rannochia"
android:textAlignment="center"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="78"
android:textAlignment="center"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="CB"
android:textAlignment="center"
android:textStyle="bold"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Dann möchte ich Iterierte durch alle CardViews in der übergeordneten und die Linearlayout Textviews bekommen. Etwas wie folgt aus:
for (int i = 0; i < defense.getChildCount(); i++){
String getName = ((CardView)defense.getChildAt(i)).getText().toString();
id[i] = getName;
}
Aber ich bin nicht in der Lage die Methoden getText().toString();
so zu nennen. Wie kann ich den Text von diesen TextViews innerhalb des CardViews erhalten?
Thank you! Es funktioniert perfekt, besonders wenn ich mehr als ein CardView habe. – Sumsar9000
Kein Problem, Mann. – Fr099y