繁体   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