Ben Becker
- Forum-Beiträge: 209
04.06.2011, 00:05:05 via Website
04.06.2011 00:05:05 via Website
Hiho!
Ich sitze jetzt schon den ganzen abend an einem Problem. Ich finde gerade mit der Programmierung von Android Apps an. Dabei scheine ich mir doch etwas sehr schwerer vorgenommen zu haben. Und zwar das Wechseln der Designs mit Tabs und einstellen von Texten in einer Tabelle. Um das hinzubekommen habe ich erst mal klein Angefangen. Hier mal meine main.xml und ArtistsActivity.java, ich würde halt gerne den Text mit der ID textView1 dynamisch setzen. Das funktioniert aber nicht. Was mache ich falsch? Wo kann ich sowas nachlesen? Am Ende soll dieses ArtistsActivity oben einen Textview hinbauen als Überschrift und darunter dann eine Tabelle 2 Zeile, 3 Spalten die dynamisch gefüllten werden. Den Abruf des Webclient habe ich schon hinbekommen.
Ich sitze jetzt schon den ganzen abend an einem Problem. Ich finde gerade mit der Programmierung von Android Apps an. Dabei scheine ich mir doch etwas sehr schwerer vorgenommen zu haben. Und zwar das Wechseln der Designs mit Tabs und einstellen von Texten in einer Tabelle. Um das hinzubekommen habe ich erst mal klein Angefangen. Hier mal meine main.xml und ArtistsActivity.java, ich würde halt gerne den Text mit der ID textView1 dynamisch setzen. Das funktioniert aber nicht. Was mache ich falsch? Wo kann ich sowas nachlesen? Am Ende soll dieses ArtistsActivity oben einen Textview hinbauen als Überschrift und darunter dann eine Tabelle 2 Zeile, 3 Spalten die dynamisch gefüllten werden. Den Abruf des Webclient habe ich schon hinbekommen.
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 <RelativeLayout
7 android:orientation="vertical"
8 android:layout_width="fill_parent"
9 android:layout_height="fill_parent">
10 <TabWidget
11 android:id="@android:id/tabs"
12 android:layout_width="fill_parent"
13 android:layout_height="wrap_content"
14 android:layout_alignParentBottom="true"/>
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 <ScrollView android:id="@+id/scrollView1" android:layout_width="fill_parent" android:layout_height="fill_parent">
21 <LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent">
22 <TextView android:text="TextView" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
23 </LinearLayout>
24 </ScrollView>
25 </FrameLayout>
26 </RelativeLayout>
27</TabHost>
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 <RelativeLayout
7 android:orientation="vertical"
8 android:layout_width="fill_parent"
9 android:layout_height="fill_parent">
10 <TabWidget
11 android:id="@android:id/tabs"
12 android:layout_width="fill_parent"
13 android:layout_height="wrap_content"
14 android:layout_alignParentBottom="true"/>
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 <ScrollView android:id="@+id/scrollView1" android:layout_width="fill_parent" android:layout_height="fill_parent">
21 <LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent">
22 <TextView android:text="TextView" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
23 </LinearLayout>
24 </ScrollView>
25 </FrameLayout>
26 </RelativeLayout>
27</TabHost>
1package de.benbecker.hellotabwidget;
2
3import org.apache.http.HttpResponse;
4import org.apache.http.client.HttpClient;
5import org.apache.http.client.methods.HttpGet;
6import org.apache.http.impl.client.DefaultHttpClient;
7import org.json.JSONObject;
8
9import android.app.Activity;
10import android.os.Bundle;
11import android.widget.TextView;
12
13public class ArtistsActivity extends Activity {
14 public void onCreate(Bundle savedInstanceState) {
15 setContentView(R.layout.main);
16 super.onCreate(savedInstanceState);
17 final String txtUrl = "http://tests.benjaminbecker.de/app.php";
18 final TextView txtResult = new TextView(this);
19
20 TextView tv = (TextView) findViewById(R.id.textView1);
21 tv.setText("HALLLLLLLLLOOOOOOOOOOOOOOOOOOOOOO");
22 setContentView(tv);
23 txtResult.setText("leer");
24 getRequest(txtResult,txtUrl);
25 TextView textview = new TextView(this);
26 textview.setText("TEST");
27 setContentView(txtResult);
28 }
29
30 public void getRequest(TextView txtResult, String txtUrl){
31 String url = txtUrl;
32 JSONObject Jarr=null;
33 HttpClient client = new DefaultHttpClient();
34 HttpGet request = new HttpGet(url);
35 try{
36 HttpResponse response = client.execute(request);
37 String text=HttpHelper.request(response);
38 try {
39 Jarr= new JSONObject(text);
40 } catch (Exception e) {
41 e.printStackTrace();
42 }
43 txtResult.setText(Jarr.getString("richtig"));
44 }catch(Exception ex){
45 txtResult.setText("Failed!");
46 }
47 }
48
49}
2
3import org.apache.http.HttpResponse;
4import org.apache.http.client.HttpClient;
5import org.apache.http.client.methods.HttpGet;
6import org.apache.http.impl.client.DefaultHttpClient;
7import org.json.JSONObject;
8
9import android.app.Activity;
10import android.os.Bundle;
11import android.widget.TextView;
12
13public class ArtistsActivity extends Activity {
14 public void onCreate(Bundle savedInstanceState) {
15 setContentView(R.layout.main);
16 super.onCreate(savedInstanceState);
17 final String txtUrl = "http://tests.benjaminbecker.de/app.php";
18 final TextView txtResult = new TextView(this);
19
20 TextView tv = (TextView) findViewById(R.id.textView1);
21 tv.setText("HALLLLLLLLLOOOOOOOOOOOOOOOOOOOOOO");
22 setContentView(tv);
23 txtResult.setText("leer");
24 getRequest(txtResult,txtUrl);
25 TextView textview = new TextView(this);
26 textview.setText("TEST");
27 setContentView(txtResult);
28 }
29
30 public void getRequest(TextView txtResult, String txtUrl){
31 String url = txtUrl;
32 JSONObject Jarr=null;
33 HttpClient client = new DefaultHttpClient();
34 HttpGet request = new HttpGet(url);
35 try{
36 HttpResponse response = client.execute(request);
37 String text=HttpHelper.request(response);
38 try {
39 Jarr= new JSONObject(text);
40 } catch (Exception e) {
41 e.printStackTrace();
42 }
43 txtResult.setText(Jarr.getString("richtig"));
44 }catch(Exception ex){
45 txtResult.setText("Failed!");
46 }
47 }
48
49}
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.