Android Layout ändern in Thread

JAVAnnik

Bekanntes Mitglied
Hallo zusammen,

ich hab schon wieder ein Problem und diesmal schaff ich es nicht selbst zu lösen. Und zwar mächte zu beginn meines Programms ein Logo für wenige Sekunden anzeigen. Dieses Logo ist im Layout 'start' enthalten. Nach den paar Sekunden möchte ich das nächste Layout 'main' anzeigen. Benutzt habe ich hierfür einen Thread, doch durch diesen bekomme ich immer nach Ablauf der Zeit und vor dem Layoutwechsel eine Fehlemeldung: the application ... has stopped...

Java:
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.start);
        
        Thread warte = new Thread(){
            @Override
            public void run(){
                try {
                	wait(3000);
                    setContentView(R.layout.main);
                }
                catch(InterruptedException ex){                    
                }             
            }
        };

        warte.start();   
    }
 

schlingel

Gesperrter Benutzer
In kurzen Worten: Das geht nicht.

Du darfst nicht aus einem anderen Thread auf Inhalte einer Viewgroup die in einem anderen Thread erzeugt wurde zugreifen. (Das würde übrigens auch in der Exception stehen, die du im Logcat findest.)

Die Frage ist, warum du nicht mit einem PopupWindow ein Overlay bastelst und das anzeigst. Das würde deutlich einfacher gehen und du hast auch erreicht was du möchtest.

Oder du verwendest die Methode runOnUiThread, ich weiß allerdings nicht ob das alles so reibungslauf läuft wenn du die Content-View austauscht.
 
T

Tomate_Salat

Gast
Jup, das gibt eine lustige "Can't touch this [NA--NA-NA-NA, NANA, NANA]"-Exception. Ich hatte etwas ähnliches mit Handler bewerkstelligt, die ich dem anderen Thread übergeben habe.
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
W Ausklappbares Verlängertes XML Layout Android & Cross-Platform Mobile Apps 6
W Android Wieso kann ich keine ListView mehr zum Layout hinzufügen? Android & Cross-Platform Mobile Apps 1
A Android-Studio: 2. Layout nach kurzer Zeit aufzeigen Android & Cross-Platform Mobile Apps 2
S Android Layout - welchen Typ? Android & Cross-Platform Mobile Apps 3
B Android Multiple Screens- layout-sw600dp Android & Cross-Platform Mobile Apps 1
D Android Layout für alle Geräte Android & Cross-Platform Mobile Apps 4
W Android Designfrage / Layout / Activity / Fragments Android & Cross-Platform Mobile Apps 2
B Layout Bibliothek Android & Cross-Platform Mobile Apps 8
B Android Spiele-Layout umsetzen Android & Cross-Platform Mobile Apps 5
O zurück Schaltfläche in voriges Layout Android & Cross-Platform Mobile Apps 5
B Erste Android-App: setContentView(R.layout.main) funktioniert nicht Android & Cross-Platform Mobile Apps 6
D Android Viele Buttons und ein Layout Android & Cross-Platform Mobile Apps 6
M Android Game, welche Layout? Android & Cross-Platform Mobile Apps 2
B Eigene View xml-Layout einbinden Android & Cross-Platform Mobile Apps 1
R Android Layout Bild mit Text Android & Cross-Platform Mobile Apps 13
K Rand bei (Table,Relative,Linear)Layout - wie bekomme ich ihn weg? Android & Cross-Platform Mobile Apps 3
D Android Layout Problem Android & Cross-Platform Mobile Apps 2
P Android Nach Animation Layout auf alten Platz Android & Cross-Platform Mobile Apps 3
T Android Layout Update Animation Android & Cross-Platform Mobile Apps 3
P Probleme mit xml-Layout Android & Cross-Platform Mobile Apps 2
W XML Layout: wann wird geladen? Android & Cross-Platform Mobile Apps 10
F Layout mit listViews (Scrolling-Probleme) Android & Cross-Platform Mobile Apps 2
G Fehlermeldung: "No XML content. Please add a root view or layout to your documet." Android & Cross-Platform Mobile Apps 7
N Android xml - graphical layout nur noch weiß :o Android & Cross-Platform Mobile Apps 4
T Android Merkwürdigkeiten im Layout Android & Cross-Platform Mobile Apps 7
A Android Browser öffnen, XML-GUI-Layout Android & Cross-Platform Mobile Apps 23
A Absolute Layout soll auf jedem Gerät gleich aussehen Android & Cross-Platform Mobile Apps 4
S Android Layout Problem mit fill_parent Android & Cross-Platform Mobile Apps 5
tfa Android Layout-Probleme: View programmatisch erweitern (addContentView) Android & Cross-Platform Mobile Apps 7
W Edit Text Drawable Icon ändern plus Funktion Android & Cross-Platform Mobile Apps 30
missy72 Android ImageView Aus- Einblenden und Ressource ändern Android & Cross-Platform Mobile Apps 1
W Pixel Farbe in eine andere Farbe ändern im ImageView von ein Icon Android & Cross-Platform Mobile Apps 14
W Rand ändern beim ImageView bei Picasso Android & Cross-Platform Mobile Apps 1
OSchriever Navigation drawer Strings ändern sich nicht Android & Cross-Platform Mobile Apps 0
AGW Android Links im Menü und Namen ändern Android & Cross-Platform Mobile Apps 2
O Android Spinner-Array ändern Android & Cross-Platform Mobile Apps 6
AGW Android Teilen Button ändern Android & Cross-Platform Mobile Apps 14
A ImageButton in ListView Item bei klick ändern Android & Cross-Platform Mobile Apps 3
S Android Style vom Spinner ändern (Dropdown sowie Fontfarbe) Android & Cross-Platform Mobile Apps 1
L Hintergrund eines Switch(Buttons) ändern Android & Cross-Platform Mobile Apps 3
Maresuke Android Android ListView Textfarbe und Texthintergrund ändern? Android & Cross-Platform Mobile Apps 5
A Fehlermeldung beim ändern der ViewGroup. Android & Cross-Platform Mobile Apps 6
H Buttons färben sich mit, beim Hintergrund ändern Android & Cross-Platform Mobile Apps 3
H Fehler Actionbar Theme ändern Android & Cross-Platform Mobile Apps 2
S Android CheckBox Status von anderer Klasse aus ändern Android & Cross-Platform Mobile Apps 4
H Radiobutton Eigenschaften ändern (in Radiogroup) Android & Cross-Platform Mobile Apps 2
G Android zur Laufzeit den Text im Menü ändern Android & Cross-Platform Mobile Apps 3
Maxim6394 [ Android ] Activity ändern Android & Cross-Platform Mobile Apps 9
Maxim6394 [Android] contentView ändern Android & Cross-Platform Mobile Apps 3
I Android Hintergrundfarbe von Textview (Shape) ändern Android & Cross-Platform Mobile Apps 19
T Android AlertDialog; Buttons ändern Android & Cross-Platform Mobile Apps 4
J Java ME vorhandes Javaprojekt in JavaME ändern Android & Cross-Platform Mobile Apps 6
G Schriftgröße in einem TextField ändern Android & Cross-Platform Mobile Apps 2
I Android Auf ImageView aus einem anderen Thread zugreifen liefert Fehlermeldung (App stürzt ab) Android & Cross-Platform Mobile Apps 5
J Android zugrif auf Thread nach Handy drehen. Android & Cross-Platform Mobile Apps 10
A Von verschiedenen Klassen auf Thread zugreifen Android & Cross-Platform Mobile Apps 2
M Android Stop Swipe Refresh aus anderem Thread Android & Cross-Platform Mobile Apps 2
ms_cikar Thread / Intent als externe klasse Android & Cross-Platform Mobile Apps 1
G Thread in einer Service erstellen Android & Cross-Platform Mobile Apps 0
M App Programmierung: Thread starten und Variablenwerte oder Objekte mitgeben Android & Cross-Platform Mobile Apps 2
A Android Von einem Thread auf anderen zugreifen Android & Cross-Platform Mobile Apps 3
C new Thread oder setRunning = true/false Android & Cross-Platform Mobile Apps 12
C Auf innere (Thread)Klasse zugreifen, von anderer Klasse aus Android & Cross-Platform Mobile Apps 3
S Android Kommunikation zwischen UI -> Service -> Thread Android & Cross-Platform Mobile Apps 4
G Pause ohne sleep und ohne zweiten Thread Android & Cross-Platform Mobile Apps 5
G Pause im Programmablauf ohne extra Thread Android & Cross-Platform Mobile Apps 2
Gossi Android Gossis Android Fragen Thread Android & Cross-Platform Mobile Apps 3
H Android ListView Images aus dem Internet via Thread Android & Cross-Platform Mobile Apps 3
L Android Thread Android & Cross-Platform Mobile Apps 4
Kidao Wie startet man ein Thread richtig? Android & Cross-Platform Mobile Apps 4
G Thread und Midlet Android & Cross-Platform Mobile Apps 1

Ähnliche Java Themen

Neue Themen


Oben