2 ListViews in einer Activity

  • 1 Antworten
  • Letztes Antwortdatum
M

Mits

Neues Mitglied
0
Hallo Leute!

Ich will in einer Activity 2 ListViews anzeigen.

Nur irgendwie stehe ich am Schlauch, ich hab bis jetzt immer nur mit einer ListView gearbeitet und wenn ich im Layout eine ListView erstellt habe dann hat das so ausgesehen:

<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="30dp"
android:textSize="25sp" />

<TextView
android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginLeft="30dp"
android:text="No data" />
Code:
setListAdapter(new CustomerInfoDetailsListAdapter(this, database.getAuftragByKdnr(customer_id)));
        getListView().setOnItemClickListener(new OnItemClickListener() {

Code:
public class CustomerInfoDetailsListAdapter extends CursorAdapter {

    private int datumIdIndex;
    //private int materialIdIndex;
    private int matBezeichnungIndex;
    //private int mengeIndex;
    private int auftragDatumIndex;
    private int auftragPreisIndex;
    
    @SuppressWarnings("deprecation")
    public CustomerInfoDetailsListAdapter(Context context, Cursor c) {
        super(context, c);    
        
        datumIdIndex = c.getColumnIndex(Auftraege.KEY_AUFT_BELEGDATUM);
        matBezeichnungIndex = c.getColumnIndex(Auftraege.KEY_AUFT_BEZEICHNUNG);
        auftragPreisIndex = c.getColumnIndex(Auftraege.KEY_AUFT_NETTOPREIS);
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        setViewInfos(view, cursor);
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View itemView = inflater.inflate(R.layout.customer_info_list_details_item, null);

        return setViewInfos(itemView, cursor);
    }
    
    private View setViewInfos(View itemView, Cursor cursor) {
        
        TextView flddatum= (TextView) itemView.findViewById(R.id.cust_datum);
        flddatum.setText(Integer.toString(cursor.getInt(datumIdIndex)));
        
        TextView fldMatBezeichnung= (TextView) itemView.findViewById(R.id.cust_material_bezeichnung);
        fldMatBezeichnung.setText(cursor.getString(cursor.getColumnIndex(Auftraege.KEY_AUFT_BEZEICHNUNG)));
        
        TextView fldpreis= (TextView) itemView.findViewById(R.id.cust_material_preis);
        fldpreis.setText(Integer.toString(cursor.getInt(auftragPreisIndex)));
                

        return itemView;
    }

}
Jetzt habe ich eine zweite erstellt mit der ID

android:id="@+id/listView2"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_weight="0.24"
android:background="@color/viewBackground"
android:drawSelectorOnTop="false"
android:textSize="25sp" />


Wie kann ich aber jetzt auf diese listView zugreifen.

Irgendwie fehlt mir da der Durchblick!

Bin für jeden Tip dankbar!

lg
Jörg
 
Wo ist jetzt dein Problem?
Erbst du in deiner Activity von ListActivity?
Dann kann es natürlich nicht gehen. Weil die komplette Activity eine Liste ist.

Erstelle einfach zwei ListViews und erbe in der Klasse von Activity.
Im Code sagst du dann:
Code:
ListView lv1 = (ListView) findViewById(R.id.list1);
ListView lv2 = (ListView) findeViewById(R.id.list2);

lv1.setListAdapter(...);
lv2.setListAdapter(...);

Gruß
 
Zurück
Oben Unten