学习Android之第五个小程序新浪微博样式(Listview的使用)
来源:互联网 发布:怎么开淘宝网点 编辑:程序博客网 时间:2024/05/20 02:23
效果图:
public SimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to)
构造函数
参数
context 关联SimpleAdapter运行着的视图的上下文。
data 一个Map的列表。在列表中的每个条目对应列表中的一行,应该包含所有在from中指定的条目
resource 一个定义列表项目的视图布局的资源唯一标识。布局文件将至少应包含哪些在to中定义了的名称。
from 一个将被添加到Map上关联每一个项目的列名称的列表
to 应该在参数from显示列的视图。这些应该全是TextView。在列表中最初的N视图是从参数from中最初的N列获取的值。
MainActivity.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<Map<String, ?>> data;@Overrideprotected 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<Map<String, ?>> getData() { data = new ArrayList<Map<String, ?>>(); Map<String, Object> data01 = new HashMap<String, Object>(); data01.put("name", "张三"); data01.put("address", "最近学习了ListView组件,于是就模仿了一下腾讯微博的样式.看起来效果不错"); data01.put("photo",R.drawable.aa); data.add(data01); data01 = new HashMap<String, Object>(); data01.put("name", "李四"); data01.put("address", "只是模仿,全都是硬编码,静态的,谢谢欣赏"); data01.put("photo",R.drawable.th); data.add(data01); return data; }@Overridepublic 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
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <ListView android:id="@+id/lv" android:layout_height="match_parent" android:layout_width="match_parent"> </ListView></RelativeLayout>
blog.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ImageButton android:id="@+id/photo" android:layout_width="50dp" android:layout_height="50dp" android:layout_marginTop="20dp" android:layout_marginLeft="10dp" android:src="@drawable/th" /> <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:layout_marginLeft="10dp" android:layout_toRightOf="@id/photo" android:text="" /> <TextView android:id="@+id/time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/name" android:layout_marginLeft="130dp" android:layout_marginTop="20dp" android:text="1分钟前" /> <TextView android:id="@+id/wenzi" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_below="@id/name" android:layout_toRightOf="@id/photo" android:layout_marginLeft="10dp" android:layout_marginTop="20dp" android:text=""/></RelativeLayout>
0 0
- 学习Android之第五个小程序新浪微博样式(Listview的使用)
- 学习Android之第六个小程序新浪微博(二)(ListView和TabActivity)
- Android程序——新浪微博(Listview使用)
- Android学习之ListView自定义样式
- android学习之ListView的基本使用
- android初级学习之ListView的使用
- 关于ListView的使用,案例:新浪微博-随便看看
- 学习Android之第一个小程序及点击事件的几种方式
- Android模仿新浪微博(自定义ListView下拉刷新)
- Android仿新浪微博ListView效果
- 学习Android之第二个小程序(startActivityForResult与onActivityResult)
- 学习Android之第三个小程序计算器(Menu、Dialog)
- 学习Android之第七个小程序头像选择(自定义对话框、Gallery、ImageSwitcher)
- 学习Android之第八个小程序文件保存(Notification、AndroidTestCase)
- Android之路——第三个Android小程序(Android的Activity显示)
- Android程序——选项卡组件和ListView组件结合模拟新浪微博
- Android ProgressBar 自定义样式(二),仿原来新浪微博图片加载样式
- 新浪微博开发之十四(AFNetworking的使用 )
- Sql分区表的管理:添加,修改,查询分区表中的数据
- linux中使用hbase出现 Failed to start master java.lang.RuntimeException: HMaster Aborted
- Spring AOP的实现原理之获取增强器Adivors
- 黑马程序员-API之【Object】、【System】、【Rutime】、【Math】、【Date】、【Calendar】
- C语言中auto,register,extern,static【转】
- 学习Android之第五个小程序新浪微博样式(Listview的使用)
- C语言 指向函数的指针
- -----------------INSTALL_FAILED_INSUFFICIENT_STORAGE 异常的解决方法
- Codeforces Round #239 (Div. 2) A~D
- hadoop 0.20.2 多文件输出
- Chapter 1 unit 2 of Bootstrap-Bootstrap Scaffolding
- POJ推荐题 POJ题 POJ入门
- [动态规划]UVA 507 - Jill Rides Again
- C++ 分割字符串