文章标题
来源:互联网 发布:网络用语薯片什么意思 编辑:程序博客网 时间:2024/06/06 07:20
第一步修改代码如下
<?xml version="1.0" encoding="utf-8"?><resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="myTitleBg"> <item name="android:background">#FF0000</item> </style> <style name="myTheme" parent="android:Theme"> <item name="android:windowNoTitle">false</item> <item name="android:windowTitleSize">30dp</item> <item name="android:windowTitleBackgroundStyle">@style/myTitleBg</item> </style></resources>第二步修改代码如下
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.view.View;import android.widget.AdapterView;import android.widget.ListView;import android.widget.SimpleAdapter;import android.widget.AdapterView.OnItemClickListener;import android.widget.Toast;//第一步:extends Activitypublic class MainActivity extends Activity { // 第二步:定义数据集合 List<Map<String, ?>> data; ListView listView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); data = getData(); // 第三步:创建SimpleAdapter绑定数据 SimpleAdapter adapter = new SimpleAdapter(this, data, R.layout.list_item, new String[] { "photo", "name", "publish", "content" }, new int[] { R.id.photo, R.id.name, R.id.publish, R.id.content }); listView=(ListView) this.findViewById(R.id.listView); listView.setAdapter(adapter); listView.setOnItemClickListener(new ListClickHandler()); } //第四步:添加单击事件 private class ListClickHandler implements OnItemClickListener{ @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { Map<String, String> item=(Map<String, String>) data.get(position); Toast.makeText(MainActivity.this, item.get("name").toString(), Toast.LENGTH_LONG).show(); } } private List<Map<String, ?>> getData() { List<Map<String, ?>> data = new ArrayList<Map<String, ?>>(); Map<String, Object> item = new HashMap<String, Object>(); item.put("photo", R.drawable.p1); item.put("name", "想想"); item.put("publish", "1分钟前"); item.put("content", "正在学习AndroidListView,嘎嘎嘎嘎嘎嘎嘎嘎嘎"); data.add(item); item = new HashMap<String, Object>(); item.put("photo", R.drawable.p2); item.put("name", "嘻嘻"); item.put("publish", "10分钟前"); item.put("content", "今天真高兴啊!"); data.add(item); item = new HashMap<String, Object>(); item.put("photo", R.drawable.p3); item.put("name", "米粒"); item.put("publish", "5分钟前"); item.put("content", "今天糗大了!"); data.add(item); item = new HashMap<String, Object>(); item.put("photo", R.drawable.p4); item.put("name", "丽丽"); item.put("publish", "1分钟前"); item.put("content", "今天遇到一件好玩的事情!"); data.add(item); item = new HashMap<String, Object>(); item.put("photo", R.drawable.p5); item.put("name", "西西"); item.put("publish", "2分钟前"); item.put("content", "今天天气真好哈!"); data.add(item); item = new HashMap<String, Object>(); item.put("photo", R.drawable.p6); item.put("name", "露露"); item.put("publish", "10分钟前"); item.put("content", "今天真高兴啊!"); data.add(item); item = new HashMap<String, Object>(); item.put("photo", R.drawable.p7); item.put("name", "美美"); item.put("publish", "2分钟前"); item.put("content", "今天真高兴啊!"); data.add(item); item = new HashMap<String, Object>(); item.put("photo", R.drawable.p8); item.put("name", "晕晕"); item.put("publish", "5分钟前"); item.put("content", "今天真高兴啊!"); data.add(item); item = new HashMap<String, Object>(); item.put("photo", R.drawable.p9); item.put("name", "嘻嘻"); item.put("publish", "4分钟前"); item.put("content", "今天真高兴啊!"); data.add(item); item = new HashMap<String, Object>(); item.put("photo", R.drawable.p10); item.put("name", "嘻嘻"); item.put("publish", "1分钟前"); item.put("content", "今天真高兴啊!"); data.add(item); return data; } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; }}
0 0
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 解决coco2dx创建的项目在通过 eclipse ndk编译时报"undefined reference to XXXX "
- 链表笔试面试题
- System.AccessViolationException类型的未经处理的异常在System.Data.dll中发
- Linux中zip压缩和unzip解压缩命令详解
- meta标签详解(整理于网络)
- 文章标题
- OpenCL与CUDA,CPU与GPU
- 内核 current宏解析
- DesignPatterns_ChainOfResponsibility
- EL表达式
- 人见人爱A^B
- 更新ubuntu 10.10的源
- 新的个人计划
- java 实现单例模式