Back

android: ListView的简单用法

发布时间: 2016-08-31 01:02:00

当你在android中看到一个  列表时, 它基本就是个ListView. 不过,还是需要通过源代码来获知的. 

它需要3个元素:  

1. ListView   ( 定义在XML 或者activity 中) 

2. Adapter    ( 定义在 activity 中, 与 ListView的实例一起使用) 

3. 数据.   

下面是个例子:

public class ListActivity ... { 

  public void onCreate(...){
    listView = new ListView(this);
    listView.setAdapter(new ArrayAdapter...,  getData());
  }

  // 在这里返回数据.
  private List getData(){

  }
}

Back