Eigene View xml-Layout einbinden

Bitstubbi

Mitglied
HeyHo,

ich habe die View-Klasse überschreiben und ein eine Activity eingebunden, weil ich onTouchEvent(MotionEvent event) überschreiben musste.
Meine neue View names "Touchpad" habe ich wie folgt in meine Activity eingebunden:

Java:
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		tp = new TouchPad(this, null);
		setContentView(tp);
	}

Die Klasse funktioniert auf top, nur sieht man leider nur einen schwarzen Bildschirm, ist ja auch klar, weil keine Referenz auf ein XML-Layout besteht. Nun würde ich gerne 2 Buttons einfügen, doch ich kann ja nicht einfach in der Activity setContentView(...) ändern, weil ich dann ja nicht meine geänderte View habe.

Gibt es eine Möglichkeit in meinem "Touchpanel" im Konstruktor o.ä. eine "XML-View" einzubinden?

Versteh ich das View//Activity-Prinzip überhaupt richtig?

Danke schon mal mfg BitStubbi
 

kaoZ

Top Contributor
Du kannst selbstverständlich , insofern dein Touchpanel eine eigenständige Activity ist ( also auch als solche in deine Manifest Datei eingetragen ist ) , mit
Code:
setContentView();
auch dieser ein eigenes Design , welches aus einer xml Datei geparst wird laden.

[EDIT]Vorraussetzung dafür das dies funktioniert ist allerdings auch das "Touchpanel" die Klasse Activity erweitert, da du sonst auf die
Code:
.onCreate()
, und ebendso
Code:
.setContentView();
methoden nicht zugreifen kannst[/EDIT]

starten würdest du diese dann ganz einfach über einen
Code:
Intent
 
Zuletzt bearbeitet:
Ähnliche Java Themen
  Titel Forum Antworten Datum
Android App auf das eigene Handy bekommen Android & Cross-Platform Mobile Apps 3
T Android Eigene App stürzt ab Android & Cross-Platform Mobile Apps 3
K Android DialogFragment eigene Argumente per Bundle übergeben Android & Cross-Platform Mobile Apps 4
X Eigene jars als libs mitgeben? Android & Cross-Platform Mobile Apps 4
R Android Zugriff auf view von MainActivity Android & Cross-Platform Mobile Apps 7
W Zur Laufzeit erstelltes MenuItem an eine View binden Android & Cross-Platform Mobile Apps 1
W Bild aus dem Internet in View bzw. ImageView laden (Fragment) Android & Cross-Platform Mobile Apps 2
J View Breite/Höhe bestimmen Android & Cross-Platform Mobile Apps 4
B Android In einem View der ersten Activity zweite anzeigen Android & Cross-Platform Mobile Apps 2
S Dynamische EditText View eingaben in Datenbank speichern Android & Cross-Platform Mobile Apps 0
V PopUp in gleicher View anzeigen Android & Cross-Platform Mobile Apps 1
M Android Suche Activity/View Namen Android & Cross-Platform Mobile Apps 1
R Android Warum (View view)? Android & Cross-Platform Mobile Apps 4
J Android neue View mit OnTouchListener Android & Cross-Platform Mobile Apps 0
R Problem mit View in ScrollView Android & Cross-Platform Mobile Apps 6
R Android Android.view Serializable ? Android & Cross-Platform Mobile Apps 3
M Android View zu View hinzufügen Android & Cross-Platform Mobile Apps 4
M Activity wechseln aus List View mit Android & Cross-Platform Mobile Apps 2
M Suche Name von View Komponente Android & Cross-Platform Mobile Apps 10
G canvas in view anzeigen Android & Cross-Platform Mobile Apps 10
G Fehlermeldung: "No XML content. Please add a root view or layout to your documet." Android & Cross-Platform Mobile Apps 7
E Android View zur Laufzeit hinzufügen Android & Cross-Platform Mobile Apps 4
N neuen view öffnen Android & Cross-Platform Mobile Apps 13
J id's von view komponenten werden nicht gefunden Android & Cross-Platform Mobile Apps 2
C Panel/View für Android Android & Cross-Platform Mobile Apps 3
tfa Android Layout-Probleme: View programmatisch erweitern (addContentView) Android & Cross-Platform Mobile Apps 7
G Dynamische View Inhalt -> Lagesensor Android & Cross-Platform Mobile Apps 3
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
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
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
JAVAnnik Android Layout ändern in Thread Android & Cross-Platform Mobile Apps 2
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

Ähnliche Java Themen

Neue Themen


Oben