Android Informationen zwischen Tabs austauschen

Nemo2478

Aktives Mitglied
Hallo an alle,

zuerst möchte ich euch den Quellcode zeigen:

main.xml:
Java:
<?xml version="1.0" encoding="UTF-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">


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

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="-4dp"
            android:layout_weight="0" />
     
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1" />

     

    </LinearLayout>
</TabHost>

MainActivity.java:
Java:
package com.mycompany.myapp3;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TabHost;
import android.widget.Toast;

public class MainActivity extends TabActivity {
    /**
     * Called when the activity is first created.
     */
    TabHost tabHost;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        tabHost = (TabHost) findViewById(android.R.id.tabhost); // initiate TabHost
        TabHost.TabSpec spec; // Reusable TabSpec for each tab
        Intent intent; // Reusable Intent for each tab

        spec = tabHost.newTabSpec("home"); // Create a new TabSpec using tab host
        spec.setIndicator(getString(R.string.coneccion)); // set the “HOME” as an indicator
        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent(this, HomeActivity.class);
        spec.setContent(intent);
        tabHost.addTab(spec);

        // Do the same for the other tabs

        spec = tabHost.newTabSpec("Contact"); // Create a new TabSpec using tab host
        spec.setIndicator("Chat"); // set the “CONTACT” as an indicator
        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent(this, ContactActivity.class);
        spec.setContent(intent);
        tabHost.addTab(spec);

     
        //set tab which one you want to open first time 0 or 1 or 2
        tabHost.setCurrentTab(0);
        tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
            @Override
            public void onTabChanged(String tabId) {
                // display the name of the tab whenever a tab is changed
                 
            }
        });
    }
}

Wie ihr seht, habe ich zwei Tabs.
In einem Tab habe ich einen EditText und ein Button.
In dem anderen Tab hab ich einen EditText.
Wenn ich auf den Button von Tab 1 tippe möchte ich, dass der Text vom EditText aus Tab 1 im EditText aus Tab 2 erscheint.
Ich hoffe, dass ihr mich versteht.

Wer erweist mir Barmherzigkeit und gibt diesem elenden Benutzer Hilfe? :(


Liebe Grüße und vielen Dank
 
Zuletzt bearbeitet:

Nemo2478

Aktives Mitglied
Ich bedanke mich für deine Antwort.

Was ich dazu erwähnen wollte (weil ich selbst die Erfahrung gemacht habe)ist, dass es viel besser ist mit TabLayout zu arbeiten, weil TabHost irgendwie alt ist...
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
S Android Speichern von Informationen in Code oder extern Android & Cross-Platform Mobile Apps 0
Julius99 Android Distanz zwischen zwei Location Android & Cross-Platform Mobile Apps 12
U Telepräsenz zwischen Notebook und Roboter Android & Cross-Platform Mobile Apps 1
M Android Kabellose Datenübertragung zwischen zwei Handys - Reichweiten Android & Cross-Platform Mobile Apps 3
? Android erstellen der grafischen Benutzeroberfläche und Kommunikation zwischen Apps Android & Cross-Platform Mobile Apps 8
K Android Datenaustausch zwischen zwei Fragments Android & Cross-Platform Mobile Apps 1
G Android Kommunikation zwischen den Activities Android & Cross-Platform Mobile Apps 1
B Android Kollision zwischen 2 Bitmaps Prüfen? Android & Cross-Platform Mobile Apps 4
R Android Datenaustausch zwischen PC und Handy Android & Cross-Platform Mobile Apps 3
S Android "Weiches wechseln" zwischen Views in einer Activity Android & Cross-Platform Mobile Apps 3
S Android Kommunikation zwischen UI -> Service -> Thread Android & Cross-Platform Mobile Apps 4
M Daten zwischen mehreren Activities Android & Cross-Platform Mobile Apps 2
M Daten zwischen Activities übergeben Android & Cross-Platform Mobile Apps 7
C Android Kommunikation zwischen Service und Activity Android & Cross-Platform Mobile Apps 8
S Android binäre Daten zwischen Android und einem Java-Server Android & Cross-Platform Mobile Apps 5
S Android Auf Funktionen zwischen Activitys zugreifen Android & Cross-Platform Mobile Apps 3
E Übergang zwischen 2 Activities Android & Cross-Platform Mobile Apps 1
G Bluetooth Verbindung zwischen Handy und PC Android & Cross-Platform Mobile Apps 5
T Unterschiede zwischen CrEme 4.1 und J9 6.1 Android & Cross-Platform Mobile Apps 3
O Bluetooth Verbindung zwischen 2 Handys Android & Cross-Platform Mobile Apps 5
T Diskrepanz zwischen SUN Toolkit und NOKIA 6610i Android & Cross-Platform Mobile Apps 3
D messages via xml zwischen server/clienthandy verschicken Android & Cross-Platform Mobile Apps 5
B Zufallszahlen zwischen 1 und 49 erstellen? aber wie? Android & Cross-Platform Mobile Apps 7
D Android Tabs nutzen - PagerTitleStrip haut nicht hin Android & Cross-Platform Mobile Apps 4
L Android ActionBar mit unterschiedlichen Farben für Tabs Android & Cross-Platform Mobile Apps 3
N Android Retain-Fragment + ActionBar-Tabs = Absturz!? Android & Cross-Platform Mobile Apps 9
D TabHost mit Tabs verschieben und Bilder einsetzen Android & Cross-Platform Mobile Apps 7
StrikeTom Android tabs ohne xml Android & Cross-Platform Mobile Apps 6

Ähnliche Java Themen

Neue Themen


Oben