急~!Android listView 怎么样显示条数? 比如:数据的条数不确定有的有5条,有的有4条应该怎么显示

2024-11-16 06:23:49
推荐回答(3个)
回答1:

  SimpleAdapter adapter = new SimpleAdapter(DialogListDemo.this,
  getData(), R.layout.listview, new String[] { "text",
  "text1", "text2", "img" }, new int[] {
  R.id.L_TextView01, R.id.L_TextView03,
  R.id.L_TextView04, R.id.L_ImageButton01 });
  lv.setAdapter(adapter);

  private List> getData() {

  List> list = new ArrayList>();
  Map map = new HashMap();
  Cursor cur = DR.query("myuser", new String[] { "userID", "psd" ,"repsd"}, null,
  null, null, null, null);

  while (cur.moveToNext()) {
  String name2 = cur.getString(0);
  String psd2 = cur.getString(1);
  String repsd= cur.getString(2);

  map.put("text",repsd);
  map.put("text1", name2);
  map.put("text2", psd2);
  map.put("img", R.drawable.a35);
  list.add(map);

  // }

  }

  我这里面是写数据插入的(片段代码) ,所以不确定要插入多少个 应用while (cur.moveToNext()) {
  }用游标对数据库进行遍历 然后插入到listview里面

回答2:

设置全局变量,每增加一个,++

回答3:

鸟人知道