ListActivity einbetten mittels <include>

  • Antworten:2
Michael K.
  • Forum-Beiträge: 6

26.07.2011, 00:11:12 via Website

Hi,

ich bin langsam am verzweifeln. Irgendwie komme ich überhaupt nicht vorwärts :(
Ich möchte eine erzeugte Liste in einen Parent einbetten. Also quasi etwas, wie:
<Text>
<Generierte Liste>
Bei mir kommt aber jedes mal nur die <Generierte Liste> heraus :(

Mein Code sieht aus wie folgt:
Mein "Parent"-Layout (menu_appointments_show) - HIER habe ich das <include>-Tag gesetzt, jedoch hat es keine Auswirkungen :(
1<?xml version="1.0" encoding="utf-8"?>
2<LinearLayout
3 xmlns:android="http://schemas.android.com/apk/res/android"
4 android:orientation="vertical"
5 android:layout_width="match_parent"
6 android:layout_height="match_parent">
7 <TextView
8 android:text="@string/t_menu_appointment_show_title"
9 android:id="@+id/t_menu_appointment_show_title"
10 android:layout_height="wrap_content"
11 android:layout_width="fill_parent"
12 android:gravity="center"
13 style="@style/title_1"/>
14 <include
15 android:layout_width="fill_parent"
16 layout="@layout/menu_appointments_show_list"/>
17</LinearLayout>
Das Layout der zu generierenden Liste (menu_appointments_show_list)
1<?xml version="1.0" encoding="utf-8"?>
2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:orientation="horizontal"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent">
6 <TextView
7 android:layout_width="wrap_content"
8 android:id="@+id/t_menu_appointments_show_id"
9 android:visibility="gone"
10 android:text="TextView"
11 android:layout_height="wrap_content"/>
12 <TextView
13 android:layout_width="wrap_content"
14 android:id="@+id/t_menu_appointments_show_date"
15 android:text="TextView"
16 android:layout_weight="1"
17 android:gravity="center"
18 android:layout_height="wrap_content"/>
19 <TextView
20 android:layout_width="wrap_content"
21 android:id="@+id/t_menu_appointments_show_time"
22 android:text="TextView"
23 android:layout_weight="1"
24 android:gravity="center"
25 android:layout_height="wrap_content"/>
26 <TextView
27 android:layout_width="wrap_content"
28 android:id="@+id/t_menu_appointments_show_patient_id"
29 android:visibility="gone"
30 android:text="TextView"
31 android:layout_height="wrap_content"/>
32 <TextView
33 android:layout_width="wrap_content"
34 android:id="@+id/t_menu_appointments_show_patient"
35 android:visibility="gone"
36 android:layout_weight="1"
37 android:layout_height="wrap_content"/>
38 <TextView
39 android:layout_width="wrap_content"
40 android:id="@+id/t_menu_appointments_show_doctor_id"
41 android:visibility="gone"
42 android:text="TextView"
43 android:layout_height="wrap_content"/>
44 <TextView
45 android:layout_width="wrap_content"
46 android:id="@+id/t_menu_appointments_show_doctor"
47 android:text="TextView"
48 android:layout_weight="1"
49 android:gravity="center"
50 android:layout_height="wrap_content"/>
51</LinearLayout>
Meine ListActivity:
1public class ShowAppointmentsActivity extends ListActivity {
2
3 private static final String TAG = new String(ShowAppointmentsActivity.class.getSimpleName());
4
5 @Override
6 public void onCreate(Bundle savedInstanceState) {
7 super.onCreate(savedInstanceState);
8 Log.d(TAG,"onCreate");
9 //LADE AUS DB
10 this.setListAdapter(new AppointmentsShowAdapter(this, response.getAppointments(),response.getDoctors()));
11 }
12//...
13}
Und zuletzt der Adapter:
1package de.luebeck.uni.itm.mss.android.tablet.appointment;
2import java.text.SimpleDateFormat;
3import java.util.List;
4import java.util.Map;
5
6import android.app.Activity;
7import android.util.Log;
8import android.view.LayoutInflater;
9import android.view.View;
10import android.view.ViewGroup;
11import android.widget.ArrayAdapter;
12import android.widget.TextView;
13import de.luebeck.uni.itm.mss.android.tablet.R;
14import de.luebeck.uni.itm.mss.xo.appointment.response.XoAppointmentGetResponse;
15import de.luebeck.uni.itm.mss.xo.user.doctor.response.XoDoctorGetResponse;
16
17public class AppointmentsShowAdapter extends ArrayAdapter<XoAppointmentGetResponse> {
18
19 private final Activity context;
20 private final List<XoAppointmentGetResponse> appointments;
21 private final Map<Integer,XoDoctorGetResponse> doctors;
22
23 public AppointmentsShowAdapter( Activity context,
24 List<XoAppointmentGetResponse> appointments,
25 Map<Integer,XoDoctorGetResponse> doctors) {
26 super(context, R.layout.menu_appointments_show, appointments);
27 this.context = context;
28 this.appointments = appointments;
29 this.doctors = doctors;
30 }
31
32 @Override
33 public View getView(int position, View convertView, ViewGroup parent) {
34 LayoutInflater inflater = context.getLayoutInflater();
35 View rowView = inflater.inflate(R.layout.menu_appointments_show_list, null, true);
36 TextView idView = (TextView) rowView.findViewById(R.id.t_menu_appointments_show_id);
37 //DATEN FÜLLEN
38 return rowView;
39 }
40}
Kann mir da einer bitte helfen?
Leider konnte ich den Code nicht einrücken.

Viele Grüße
Michi

— geändert am 26.07.2011, 00:43:19

Antworten
Michael K.
  • Forum-Beiträge: 6

26.07.2011, 00:55:45 via Website

Habe es gelöst, ich weiß jedoch nicht, ob es der sauberste Weg ist (vgl. http://stackoverflow.com/questions/1254074/how-to-call-the-setlistadapter-in-android):
1. Ich habe statt "extends ListActivity" in der AppointmentsShowActivity eine normale "extends Activity" verwendet.
2. Im "Parent-Layout" habe ich statt include <ListView> verwendet
3. Die onCreate-Methode sieht nun folgendermaßen aus:
1@Override
2 public void onCreate(Bundle savedInstanceState) {
3 super.onCreate(savedInstanceState);
4 Log.d(TAG,"onCreate");
5 setContentView(R.layout.menu_appointments_show);
6 //LADE AUS DB
7 ListView listView = (ListView)findViewById(R.id.list);
8 listView.setAdapter(new AppointmentsShowAdapter(this, response.getAppointments(),response.getDoctors()));
9 }

Über Feedback würde ich mich freuen, also wie man die >ListActivity< erfolgreich erbt und implementiert mit einem Parent!

Antworten
Michael K.
  • Forum-Beiträge: 6

26.07.2011, 01:16:36 via Website

Habs nun endgültig herausgefunden:
1public class ShowAppointmentsActivity extends ListActivity {
2
3 private static final String TAG = new String(ShowAppointmentsActivity.class.getSimpleName());
4
5 @Override
6 public void onCreate(Bundle savedInstanceState) {
7 super.onCreate(savedInstanceState);
8 Log.d(TAG,"onCreate");
9 setContentView(R.layout.menu_appointments_show);
10 //LADE AUS DER DB
11 setListAdapter(new AppointmentsShowAdapter(this, response.getAppointments(),response.getDoctors()));
12 }
13
14 @Override
15 protected void onListItemClick(ListView l, View v, int position, long id) {
16 super.onListItemClick(l, v, position, id);
17 // Get the item that was clicked
18 Object o = this.getListAdapter().getItem(position);
19 String keyword = o.toString();
20 Toast.makeText(this, "You selected: " + keyword, Toast.LENGTH_LONG).show();
21 }
22}
Und im Parent-Layout muss die ListView das Attribut android:id="@android:id/list" enthalten, vgl. http://www.vogella.de/articles/AndroidListView/article.html#listadvanced_longclick

Sorry für den Spam, hoffe aber das es auch anderen hilft!

Antworten