设为首页 加入收藏

TOP

Android的listview的原始初衷(入门-->会用)
2015-02-02 22:44:19 来源: 作者: 【 】 浏览:26
Tags:Android listview 原始 初衷 入门 --> 会用

??????? ListView:包含一个垂直滚动、水平填充的View对象列表,一般来说,其中的每一项都包含一行数据;用户可以选择其中的一项执行某些操作。


???????? 用个实例来跑一下给大家看看把。代码如下:


???????? 在Activity类的onCreate()方法中添加下列代码:


???????? //找到ListView
??????? ListView mListView? = (ListView)findViewById(R.id.listView01);
???????
??????? //定义数组
??????? String[] data ={


????????????????? "-------------1-------------",
??????? ????????? "-------------2-------------",
??????? ????????? "-------------3-------------",
??????? ????????? "-------------3-------------",
??????? ????????? "-------------4-------------",
??????? ????????? "-------------5-------------",
??????? ????????? "-------------6-------------",
??????? ????????? "-------------7-------------",
??????? ????????? "-------------8-------------"};
???????
??????? //为ListView提供数组适配器
??????? /*
????????????? ■android.R.layout.simple_list_item_1?? 一行text
??????????? ? ■android.R.layout.simple_list_item_2?? 一行title,一行text
????????? ??? ■android.R.layout.simple_list_item_single_choice?? 单选按钮
??????????? ? ■android.R.layout.simple_list_item_multiple_choice?? 多选按钮
??????????? ? ■android.R.layout.simple_list_item_checked??? checkbox
?????? ?*/
??????? //创建ArrayAdapter适配器
??????? ArrayAdapter mAdapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,data);
??????? //将ArrayAdapter适配器添加到listview
??????? mListView.setAdapter(mAdapter);


????????????? 执行的结果如下:



?????? 使用CursorAdapter


?


?


????? 以上是ListView经常要用到的两个适配器。代码大家都看到了,不要我给大家总结,大家也应该会知道。


????????ListView的实现通常是下面几个步骤:


1.在ListView上显示的数据(数组或者数据库取出来的)准备好;


2.适配器(CursorAdapter或者ArrayAdapter);


3.配器添加到listView,最终显示在手机屏幕上。?


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android UI 优化 使用<include.. 下一篇C++ vector<string> 内联函..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: