ListActivity und TabActivity

  • Antworten:3
Thomas Heinze
  • Forum-Beiträge: 4

10.01.2011, 22:01:31 via Website

Hallo,

schreibe gerade eine App.

Nun habe ich eine ListView mit ListActivity. Wenn ich auf einen Eintrag in der Liste klicke möchte ich als nächstes eine Seite mit den Tabs aufrufen.

Bis zu dem Punkt auf die ListItems zu klicken funktioniert alles, danach stürzt die App ab.

Fehler:
101-10 20:49:16.884: WARN/ActivityManager(70): Force finishing activity de.thomasheinze.test/.tabList
201-10 20:49:16.904: WARN/ActivityManager(70): Force finishing activity de.thomasheinze.test/.showList

Die Scripte sehen so aus:
die list_item.xml
1<?xml version="1.0" encoding="utf-8"?>
2<TextView xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="fill_parent"
4 android:layout_height="fill_parent"
5 android:padding="10dp"
6 android:textSize="16sp"
7 android:background="@color/bblue">
8</TextView>

die showList.java
1import android.app.*;
2import android.content.Intent;
3import android.os.Bundle;
4import android.util.Log;
5import android.view.Menu;
6import android.view.MenuInflater;
7import android.view.MenuItem;
8import android.view.View;
9import android.widget.AdapterView;
10import android.widget.AdapterView.OnItemClickListener;
11import android.widget.ArrayAdapter;
12import android.widget.ListView;
13import android.widget.Toast;
14import android.widget.TextView;
15
16
17import java.io.BufferedReader;
18import java.io.InputStream;
19import java.io.InputStreamReader;
20import java.util.ArrayList;
21
22import org.apache.http.HttpEntity;
23import org.apache.http.HttpResponse;
24import org.apache.http.client.HttpClient;
25import org.apache.http.client.methods.HttpPost;
26import org.apache.http.impl.client.DefaultHttpClient;
27import org.json.JSONArray;
28import org.json.JSONException;
29import org.json.JSONObject;
30
31public class showList extends ListActivity
32 {
33
34 public static final String KEY_122 = "http://xx.xx.xx.xx/apps/testandroid.php";
35
36 //private ListView listView;
37
38 public void onCreate(Bundle savedInstanceState) {
39 super.onCreate(savedInstanceState);
40 //setContentView(R.layout.showlist);
41
42 setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, getCurrentList()));
43
44 ListView lv = getListView();
45
46 lv.setOnItemClickListener(new OnItemClickListener() {
47 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
48 //setContentView(R.layout.tabs);
49 //Intent intent = new Intent().setClass(this,tabList.class);
50 Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
51 Toast.LENGTH_SHORT).show();
52 Intent intent = new Intent(parent.getContext(), tabList.class);
53 showList.this.startActivity(intent);
54
55 }
56 });
57 }
58
59 /**********************************
60 * Menüs
61 *
62 */
63
64 @Override
65 public boolean onCreateOptionsMenu(Menu menu) {
66 super.onCreateOptionsMenu(menu);
67 MenuInflater mi =
68 new MenuInflater(getApplication());
69 mi.inflate(R.menu.hmenu, menu);
70 return true;
71 }
72
73 public boolean onOptionsItemSelected(MenuItem item) {
74 switch (item.getItemId()) {
75 case R.id.opt_appExit: {
76 quit();
77 return true;
78 }
79
80 }
81 return super.onContextItemSelected(item);
82 }
83
84 private void quit() {
85 // TODO Auto-generated method stub
86 System.exit(0);
87 }
88
89 public ArrayList<String> getCurrentList() {
90
91 //New line below
92 InputStream is = null;
93 ArrayList<String> testList = new ArrayList<String>();
94 String result = "";
95
96 try{
97
98 HttpClient httpclient = new DefaultHttpClient();
99 HttpPost httppost = new HttpPost(KEY_122);
100 HttpResponse response = httpclient.execute(httppost);
101 HttpEntity entity = response.getEntity();
102
103 // InputStream is = entity.getContent();
104 is = entity.getContent();
105
106 }catch(Exception e){
107 Log.e("log_tag", "Error in http connection "+e.toString());
108 }
109
110 //convert response to string
111
112 try{
113
114 BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
115 StringBuilder sb = new StringBuilder();
116 String line = null;
117
118 while ((line = reader.readLine()) != null) {
119 sb.append(line + "\n");
120 }
121 is.close();
122 result=sb.toString();
123 Log.i("log_info","Info Result: " + result);
124
125 }catch(Exception e){
126
127 Log.e("log_tag", "Error converting result "+e.toString());
128 }
129 //parse json data
130 try{
131 JSONArray jArray = new JSONArray(result);
132 for(int i=0;i<jArray.length();i++){
133 JSONObject json_data = jArray.getJSONObject(i);
134 testList.add(json_data.getString("j_desc"));
135
136 }
137 }catch(JSONException e){
138 Log.e("log_tag", "Error parsing data "+e.toString());
139 }
140 return testList;
141
142 }

Also in Zeile 52 und 53 aus diesem Listing ist der Fehler

die tabs.xml
1<?xml version="1.0" encoding="utf-8"?>
2<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
3 android:id="@android:id/tabhost"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent">
6 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
7 android:orientation="vertical"
8 android:layout_width="fill_parent"
9 android:layout_height="fill_parent"
10 android:padding="5dp">
11 <TabWidget
12 android:id="@android:id/tabs"
13 android:layout_width="fill_parent"
14 android:layout_height="wrap_content" />
15 <FrameLayout
16 android:id="@android:id/tabcontent"
17 android:layout_width="fill_parent"
18 android:layout_height="fill_parent"
19 android:padding="5dp" />
20 </LinearLayout>
21</TabHost>

die tabList.java
1import android.app.TabActivity;
2import android.content.Intent;
3import android.os.Bundle;
4import android.util.Log;
5import android.widget.TabHost;
6
7public class tabList extends TabActivity {
8
9 public void onCreate(Bundle savedInstanceState) {
10 super.onCreate(savedInstanceState);
11 setContentView(R.layout.tabs);
12
13 TabHost tabHost = getTabHost(); // The activity TabHost
14 TabHost.TabSpec spec; // Resusable TabSpec for each tab
15 Intent intent; // Reusable Intent for each tab
16
17 // Create an Intent to launch an Activity for the tab (to be reused)
18 intent = new Intent(this, OverView.class);
19
20 spec = tabHost.newTabSpec("oview").setIndicator("Übersicht",null)
21 .setContent(intent);
22 tabHost.addTab(spec);
23
24 tabHost.setCurrentTab(1);
25
26
27
28 }
29
30}

Ich habe keine Ahnung wo der Fehler ist.

Vielleicht kann mir jemand ein wenig helfen.

Danke

Thomas

Antworten
Mac Systems
  • Forum-Beiträge: 1.727

10.01.2011, 23:20:50 via Website

private void quit() {
85 // TODO Auto-generated method stub
86 System.exit(0);
87 }

Sowas gehört in keine Android APP!

Windmate HD, See you @ IO 14 , Worked on Wundercar, Glass V3, LG G Watch, Moto 360, Android TV

Antworten
Ansgar M
  • Forum-Beiträge: 1.544

11.01.2011, 00:53:21 via App

Versuch doch mal
1startActivity(new Intent(showList.this, tabList.class));
Wenn das nicht klappt, poste bitte mal mehr vom Logcat..
Lg Ansgar

— geändert am 11.01.2011, 00:53:56

Antworten
Thomas Heinze
  • Forum-Beiträge: 4

12.01.2011, 16:28:32 via Website

Danke, das hat geklappt.

Ansgar M
Versuch doch mal
1startActivity(new Intent(showList.this, tabList.class));
Wenn das nicht klappt, poste bitte mal mehr vom Logcat..
Lg Ansgar

Antworten