解释一下,里面用到的一些属性:
1.paddingBottom="3dip",Layout往底部留出3个像素的空白区域
2.paddingLeft="10dip",Layout往左边留出10个像素的空白区域
3.textSize="30dip",TextView的字体为30个像素那么大。
最后就是JAVA的源代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//绑定XML中的ListView,作为Item的容器
ListView list = (ListView) findViewById(R.id.MyListView);
//生成动态数组,并且转载数据
ArrayList<HashMap<String, String>> mylist =new ArrayList<HashMap<String, String>>();
for(inti=0;i<30;i++)
{
HashMap<String, String> map = newHashMap<String, String>();
map.put("ItemTitle","This is Title.....");
map.put("ItemText","This is text.....");
mylist.add(map);
}
//生成适配器,数组===》ListItem
SimpleAdapter mSchedule =new SimpleAdapter(this,//没什么解释
mylist,//数据来源
R.layout.my_listitem,//ListItem的XML实现
//动态数组与ListItem对应的子项
new String[] {"ItemTitle","ItemText"},
//ListItem的XML文件里面的两个TextView ID
new int[] {R.id.ItemTitle,R.id.ItemText});
//添加并且显示
list.setAdapter(mSchedule);
}
//数据库获取数据
DBHelper helper=new DBHelper(this);
Cursor c=helper.query();
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
int i=0;
while (c.moveToNext()) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("title",c.getString(c.getColumnIndex("Title")));
map.put("date",c.getString(c.getColumnIndex("Date")));
mylist.add(map);
i++;
}
String[] from={"title","date"};
int[] to={R.id.ItemTitle,R.id.ItemDate};
SimpleAdapter ada=new SimpleAdapter(this,mylist,R.layout.listitem,from,to);
ListView list = (ListView) findViewById(R.id.MyListView);
list.setAdapter(ada);