Android Problem mit ListActivity

Holger

Aktives Mitglied
Hey Leute, also habe ein Grundlayout von einer Category-Ansicht wo ich ein List View drin habe. Aber sobald ich in die Activity wechsel, wird die App geschlossen. Habe zu dem Problem keine passende Antwort im Forum und auch nicht wirklich bei google gefunden. Kann mir wer erklären wie ich in einer normalen Activity ein ListView befüllen kann und den OnItemClickListener setzen kann?

Java:
import android.app.ListActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.Toast;
import android.content.Intent;

public class CategoryActivity extends ListActivity{
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.categorylayout);
		ActivityRegistry.register(this);
		
		String[] categoryText = getResources().getStringArray(R.array.categoryString);
		setListAdapter(new ArrayAdapter<String>(this, R.layout.category_item, categoryText));
		ListView lv = (ListView)findViewById(R.id.CategoryList);
		//getListView();
		lv.setOnItemClickListener(new OnItemClickListener(){

			public void onItemClick(AdapterView<?> parent, View view, int position,
					long id) {
				// TODO Auto-generated method stub
				Toast.makeText(CategoryActivity.this, "Test", Toast.LENGTH_SHORT).show();
			}
			
		});
		
		final ImageButton homebutton = (ImageButton) findViewById(R.id.HomeButtonCat);
		final ImageButton categorybutton = (ImageButton) findViewById(R.id.CategoryButtonCat);
		homebutton.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent startpageIntent = new Intent(CategoryActivity.this, StartpageActivity.class);
				startActivity(startpageIntent);
				
			}

		});

		categorybutton.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent categoryIntent = new Intent(CategoryActivity.this, CategoryActivity.class);
				startActivity(categoryIntent);
			}

		});

	}
	
	public boolean onCreateOptionsMenu(Menu menu){
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.optionsmenu, menu);
		return true;
	}
	public boolean onOptionsItemSelected(MenuItem item){
		switch (item.getItemId()){
		case R.id.exit:
			exit();
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	
	}
	public void exit(){
		ActivityRegistry.finischAll();
	}

}
So sieht die Activity bis jetzt aus, funktioniert aber leider nicht und wie gesagt ich finde den Fehler nicht :/

Das Layout zu der Activity sieht so aus:
[XML]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:eek:rientation="vertical" >

<TextView
android:id="@+id/Banner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Banner"
android:textSize="40dp"
android:typeface="monospace" >
</TextView>

<TextView
android:id="@+id/headstart"
android:text="Kategorien"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="20dp"
android:background="@color/topiccolor"/>

<ListView
android:id="@+id/CategoryList"
android:layout_width="match_parent"
android:layout_height="355dp"
android:layout_weight="0.15"
android:visibility="visible"
android:layout_margin="5dp" >
</ListView>
<LinearLayout
android:eek:rientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent">

<ImageButton
android:id="@+id/HomeButtonCat"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="0.5"
android:src="@drawable/ic_launcher"
android:background="#000000" />



<ImageButton
android:id="@+id/CategoryButtonCat"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="0.5"
android:src="@drawable/ic_launcher"
android:background="#000000"/>

</LinearLayout>


</LinearLayout>
[/XML]

Und das listitem:
[XML]
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:textSize="16dp">
</TextView>
[/XML]

Danke für eure Hilfe!
 

Holger

Aktives Mitglied
Also die ActivityRegistry ist eine Klasse die ich mir geschrieben habe, die in einer ArrayList alle Activitys die gestartet werden speichert und beim Aufruf dieser Methode das Array durchläuft und alle in dem Array liegenende Activitys mit .finisch() beendet.

Also das funktioniert auch. Also bis zu dem Zeitpunkt zumindest als ich die Listviw noch nicth mit drin hatte. Kann dir den Code dazu morgen gerne nochmal eben posten!
 

schlingel

Gesperrter Benutzer
Eines vorweg: der Lifecycle einer Activity ist vom Android-System vorgegeben. Das Paradigma ist ein anderes als dass der Anwendungen auf dem Desktop. Solche Umbauten wie du sie da gemacht hast passen nicht zum Activity-Lifecycle wie er hier definiert wird. Es gab im Forum auch schon eine Diskussion zu dem Thema.

So, nach so viel nicht helfendem Blabla: Ich vermute, dass dir die ActivityRegistry die ganzen Activities beendet wenn du auf die Listview wechselst. Ich hab am Code jetzt jedenfalls nichts falsches gesehen.

Häng dich mal mit dem Debugger rein und schau wie weit du im onConstruct kommst. Da du keine Exception bekommst (hast du das schon im Logcat geprüft?) wird's das wohl sein.
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
W Prüfen, ob App auf Gerät installiert ist Problem S10 Android & Cross-Platform Mobile Apps 11
W In App Purchase Problem? Android & Cross-Platform Mobile Apps 36
W Problem mit Android Studio Android & Cross-Platform Mobile Apps 0
T Android R.string.test+i Problem Android & Cross-Platform Mobile Apps 2
K Android to Pi | Websocket Problem Android & Cross-Platform Mobile Apps 3
N Intent und finish() Problem Android & Cross-Platform Mobile Apps 5
B Android App Programmierung Einsteiger Problem Android & Cross-Platform Mobile Apps 4
emeraldo Android Problem mit Bottomnavmenu Android & Cross-Platform Mobile Apps 10
I Das Problem mit der Tastatur... android:windowSoftInputMode="adjustPan" Android & Cross-Platform Mobile Apps 1
M Android App → Problem mit dem Speichern von einem Bitmap–Objekt. Android & Cross-Platform Mobile Apps 1
A Android Android Studio Emulator Problem Android & Cross-Platform Mobile Apps 1
S Android Studio Bluetooth App Problem Android & Cross-Platform Mobile Apps 6
J TicTacToe Problem bei kontrolle Android & Cross-Platform Mobile Apps 7
J Button array ID Problem Android & Cross-Platform Mobile Apps 2
M Problem bei Werteübergabe, MSQL verbindung Android & Cross-Platform Mobile Apps 3
S Android Problem mit Android Virtual Device erstellung. Android & Cross-Platform Mobile Apps 2
Anfänger2011 Text to Speech Problem Android & Cross-Platform Mobile Apps 1
S Android Android java onclick listener Problem Android & Cross-Platform Mobile Apps 9
A Android Problem mit ListView und OnItemClickListener.. Android & Cross-Platform Mobile Apps 10
K Problem mit arraylist und button Android & Cross-Platform Mobile Apps 16
R W-Lan Problem über Sockets Android & Cross-Platform Mobile Apps 1
P ViewPager Problem Android & Cross-Platform Mobile Apps 1
A Android Problem mit Video von Youtube abspielen Android & Cross-Platform Mobile Apps 4
A Android Problem mit Zurücktaste und ausgabe der Aktuellen Seite Android & Cross-Platform Mobile Apps 6
B Android Problem mit Soundwiedergabe Android & Cross-Platform Mobile Apps 2
T Android Android Sensor: Java Problem Android & Cross-Platform Mobile Apps 1
G Problem beim Rendern von 3D-Objekt Android & Cross-Platform Mobile Apps 0
L Android Gyroscope Sensor Problem Android & Cross-Platform Mobile Apps 2
S Android GPS Problem Android & Cross-Platform Mobile Apps 24
J Eclipse Emulator Problem Android & Cross-Platform Mobile Apps 1
J Eclipse Emulator Problem Android & Cross-Platform Mobile Apps 0
B Android Problem mit Rückgabewert Android & Cross-Platform Mobile Apps 13
L Android komisches Bitmap-Größe-Problem Android & Cross-Platform Mobile Apps 8
D Android Layout Problem Android & Cross-Platform Mobile Apps 2
R Problem mit View in ScrollView Android & Cross-Platform Mobile Apps 6
R Eclipse + AndroidSDK - Problem mit Referenzen Android & Cross-Platform Mobile Apps 6
M Problem mit setOnClickListener Android & Cross-Platform Mobile Apps 4
DaniSahne96 Problem beim Appdebuggen auf Smartphone Android & Cross-Platform Mobile Apps 3
P Android Problem beim Widget - Denkfehler ? Android & Cross-Platform Mobile Apps 2
M GCM IntentService Problem Android & Cross-Platform Mobile Apps 3
D Android Gallery Problem Android & Cross-Platform Mobile Apps 5
P Problem mit Cell id Android & Cross-Platform Mobile Apps 6
L Android Problem mit "spinner" Android & Cross-Platform Mobile Apps 10
D Android problem mit geschwindigkeitsberechnung app Android & Cross-Platform Mobile Apps 2
E Android Problem mit Contact Provider Android & Cross-Platform Mobile Apps 1
S Android Layout Problem mit fill_parent Android & Cross-Platform Mobile Apps 5
F Android ExpandableList, SimpleCursorTreeAdapter, Cursor Problem Android & Cross-Platform Mobile Apps 2
A Android Problem mit Long.getLong() bzw. Integer.getInteger() Android & Cross-Platform Mobile Apps 2
A Problem mit HTTP- Verbindung Android & Cross-Platform Mobile Apps 4
V [Java] und [JavaME] ClientServer StreamConnection . Problem beim lesen / schreiben Android & Cross-Platform Mobile Apps 2
F Eclipse JAD File erzeugen -- Problem Android & Cross-Platform Mobile Apps 10
R Ein Problem beim ausführen von folgendem Quelltext Android & Cross-Platform Mobile Apps 11
M Problem mit dem Auslesen von System Properties Android & Cross-Platform Mobile Apps 7
P wtk problem Android & Cross-Platform Mobile Apps 3
G Math exp() Problem Android & Cross-Platform Mobile Apps 4
G S40 Problem Android & Cross-Platform Mobile Apps 8
A Problem beim Subtrahieren eines Double von einem Double Android & Cross-Platform Mobile Apps 5
C Problem Device/Emulator wird nicht erkannt Android & Cross-Platform Mobile Apps 3
S Image Problem Android & Cross-Platform Mobile Apps 11
M Problem mit den Softkeys Android & Cross-Platform Mobile Apps 4
G J2ME jar-problem Android & Cross-Platform Mobile Apps 10
S Komisches Problem Android & Cross-Platform Mobile Apps 3
F Problem beim Erstellen der Jar File Android & Cross-Platform Mobile Apps 4
A Problem: Canvas-Grösse Motorola RAZR v3r Android & Cross-Platform Mobile Apps 8
S Problem mit Einbindung einer externer Bibliothek Android & Cross-Platform Mobile Apps 2
G Random - Problem Android & Cross-Platform Mobile Apps 5
E problem mit den resourcen Android & Cross-Platform Mobile Apps 2
O Problem mit Datagramconnection Android & Cross-Platform Mobile Apps 2
P Problem mit der Uhrzeit Android & Cross-Platform Mobile Apps 2
S Problem auf dem Handy Android & Cross-Platform Mobile Apps 3
K OnItemLongClickListener in ListActivity spricht nicht an Android & Cross-Platform Mobile Apps 8

Ähnliche Java Themen

Neue Themen


Oben