IT rekvalifikace s garancí práce. Seniorní programátoři vydělávají až 160 000 Kč/měsíc a rekvalifikace je prvním krokem. Zjisti, jak na to!
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.

Diskuze: Android Studio - přepsání textu z jiné layoutu

V předchozím kvízu, Online test znalostí Java, jsme si ověřili nabyté zkušenosti z kurzu.

Aktivity
Avatar
Jakub Klindera:15.12.2017 14:45

Zdravím,
dělám MatchCounter a mám 2 týmy. Tým A a Tým B. V menu mám odkaz na další layout, kde můžu pojmenovat týmy

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

        <EditText
            android:id="@+id/ptA"
            android:layout_width="match_parent"
            android:layout_height="140px"
            android:gravity="center"
            android:layout_marginTop="30dp"
            android:ems="10"
            android:inputType="textPersonName"
            android:singleLine="true"
            android:text="Tým A" />

        <EditText
            android:id="@+id/ptB"
            android:layout_width="match_parent"
            android:layout_height="140px"
            android:gravity="center"
            android:layout_marginTop="80dp"
            android:ems="10"
            android:inputType="textPersonName"
            android:singleLine="true"
            android:text="Tým B" />

    <Button
        android:id="@+id/btnChange"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_marginTop="100dp"
        android:onClick="prejmenuj"
        android:text="Změnit názvy týmů" />
</LinearLayout>

A potřebuju, aby se mi přepsalo to co zadám z toho EditText do hlavního Layoutu do Textview (id tam mám ntA, ntB)

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="5"
                android:text="Tým A"
                android:id="@+id/ntA"
                />

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1">

                <TextView
                    android:id="@+id/body_a"
                    style="@style/points"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="0" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="2"
                    android:orientation="vertical">

                    <Button
                        android:id="@+id/btn_plusa"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:onClick="body"
                        android:text="+" />

                    <Button
                        android:id="@+id/btn_minusa"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:onClick="body"
                        android:text="-" />
                </LinearLayout>

            </TableRow>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="5"
                android:text="Tým B"
                android:id="@+id/ntB"/>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1">

                <TextView
                    android:id="@+id/body_b"
                    style="@style/points"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="15" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="2"
                    android:orientation="vertical">

                    <Button
                        android:id="@+id/btn_plusb"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:onClick="body"
                        android:text="+" />

                    <Button
                        android:id="@+id/btn_minusb"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:onClick="body"
                        android:text="-" />
                </LinearLayout>

            </TableRow>

        </LinearLayout>

        <TextView
            android:id="@+id/time"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:text="00:00:00" />

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="3">

            <Button
                android:id="@+id/btnStart"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="Start" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="Pauza" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="Stop" />

            <Button
                android:id="@+id/btnReset"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:onClick="btnResetClick"
                android:text="Reset" />
        </TableRow>

    </LinearLayout>

Problém je v tom, že nevím, jak to napsat v Javě, aby to bylo funkční. Metodu už mám vygenerovanou

public void prejmenuj(View view) {


        setContentView(R.layout.activity_match_counter);

    }

Děkuji

 
Odpovědět
15.12.2017 14:45
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.

Zobrazeno 1 zpráv z 1.