你好,游客 登录 注册 搜索
背景:
阅读新闻

Android基础教程:使用ListView显示信息

[日期:2011-10-30] 来源:Linux社区  作者:kukulongzai_123 [字体:大 中 小]

以显示注册信息为例:

一、创建带有ListView的Activity要继承ListActivity

this.setContentView(R.layout.user);

二、ListActivity的布局文件user.xml

<ListView

Android:id="@id/android:list"

andoid:scrollbars="vertical"

android:drawSelectorOnTop="false">

三、使用intent获得用户保存的信息

Intent intent = getIntent();

String username = intent.getStringExtra("username");

 


四 、创建要显示的list内容

HashMap<String,String> map1 = new HashMap<String,String>();

..

map1.put("user_key","姓名");

map 1.put("user_value",username);

...

//对数组进行拆分

String hob = "";

for(String h:hobby){

hob += h=" ";

}

List<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();

list.add(map1);

...

五、设置适配器

设置list.xml布局文件;

指定list控件

SimpleAdapter adapter = new SimpleAdapter(this,list,R.layout.list,

new String[]{"user_key","user_value"},

new int[]{R.id.userkey,R.id.uservlaue}

);

setListAdapter(adapter);

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款