首页 > 程序开发 > 移动开发 > Android >

学习Android之第五个小程序腾讯微博样式(Listview的使用)

2014-04-12

效果图: public SimpleAdapter(Context context, List> data, int resource, String[] from, int[] to) 构造函数 参数 context 关联SimpleAdapter运行着的视图的上下文

效果图:

\


public SimpleAdapter(Context context, List> data, int resource, String[] from, int[] to)

构造函数

参数

context 关联SimpleAdapter运行着的视图的上下文。

data 一个Map的列表。在列表中的每个条目对应列表中的一行,应该包含所有在from中指定的条目

resource 一个定义列表项目的视图布局的资源唯一标识。布局文件将至少应包含哪些在to中定义了的名称。<喎"http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+ZnJvbSAgICAgICDSu7j2vauxu8ztvNO1vU1hcMnPudjBqsO/0ru49s/uxL+1xMHQw/uzxrXEwdCx7TwvcD4KPHA+dG8gICAg06a4w9Tass7K/WZyb23P1Mq+wdC1xMrTzbyho9Xi0KnTprjDyKvKx1RleHRWaWV3oaPU2sHQse3W0Nfus/W1xE7K0828yse007LOyv1mcm9t1tDX7rP1tcROwdC78cihtcQmIzIwNTQwO6GjPC9wPgo8YnI+CjxwPjxicj4KPC9wPgo8cD48YnI+CjwvcD4KPHA+TWFpbkFjdGl2aXR5LmphdmE8YnI+CjwvcD4KPHA+PGJyPgo8L3A+CjxwPjwvcD4KPHByZSBjbGFzcz0="brush:java;">package cn.edu.bzu.micro_blog.activity; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.widget.ListView; import android.widget.SimpleAdapter; public class MainActivity extends Activity { private ListView listView; List> data; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView = (ListView)findViewById(R.id.lv); SimpleAdapter simpleAdapter = new SimpleAdapter(MainActivity.this, getData(), R.layout.blog, new String[]{ "name","address","photo"}, new int[]{R.id.name,R.id.wenzi,R.id.photo}); listView.setAdapter(simpleAdapter); } public List> getData() { data = new ArrayList>(); Map data01 = new HashMap(); data01.put("name", "张三"); data01.put("address", "最近学习了ListView组件,于是就模仿了一下腾讯微博的样式.看起来效果不错"); data01.put("photo",R.drawable.aa); data.add(data01); data01 = new HashMap(); data01.put("name", "李四"); data01.put("address", "只是模仿,全都是硬编码,静态的,谢谢欣赏"); data01.put("photo",R.drawable.th); data.add(data01); return data; } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
activity_main.xml



    
        
        
    


blog.xml





    

    

    
    
    





相关文章
最新文章
热点推荐