簡體   English   中英

在ListView中設置TextView的文本

[英]Set Text of TextView in ListView

在我的ListView中,我這樣保存數據:

public void listview_fuellen(){
    DBHelper db = new DBHelper(this);

    ListView lv = (ListView) findViewById(R.id.lvKinder);
    Cursor c = db.select();
    int count = c.getCount();

    TextView tv = (TextView) findViewById(R.id.secondLine);
    List<String> auswahl = new ArrayList<String>();
    List<String> auswahl1 = new ArrayList<String>();
    int i = 0;
    System.out.println("$$$$$$$$$$$$$$$$$$$$$$$1" + c.getCount());
    while(c.moveToNext())
    { 

        auswahl.add(c.getString(c.getColumnIndex("name")));
        auswahl1.add(" " + i);
        System.out.println("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS" + auswahl.get(i).toString());

        i++;
    }

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_black_text,R.id.firstLine, auswahl);
    //ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this, R.layout.list_black_text,R.id.secondLine, auswahl1);

    lv.setAdapter(adapter);

}

現在,我從這里嘗試了ListView的布局:

http://android-developers.blogspot.co.at/2009/02/android-layout-tricks-1.html

現在,如何為每個ListView-Item或圖標中的第二行設置值?

編輯:

我現在嘗試這樣,但是列表視圖中沒有條目。

ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
    HashMap<String, String> map =  new HashMap<String, String>();;




    int i = 0;
    System.out.println("$$$$$$$$$$$$$$$$$$$$$$$1" + c.getCount());
    while(c.moveToNext())
    { 
        //map = new HashMap<String, String>();
        map.put("name",c.getString(c.getColumnIndex("name")));
        map.put("datum", c.getString(c.getColumnIndex("zeit")));


        i++;
    }
    mylist.add(map);

   SimpleAdapter mSchedule = new SimpleAdapter(this, mylist, R.layout.list_black_text, new String[] { "datum",
         "name" }, new int[] { R.id.firstLine, R.id.secondLine });

    lv.setAdapter(mSchedule);
    setListAdapter(mSchedule);

我做錯了什么?

為此,您可以制作一個自定義適配器,然后可以為每個ListView-Item中的第二行設置值。

您可以檢查此鏈接http://devtut.wordpress.com/2011/06/09/custom-arrayadapter-for-a-listview-android/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM