在昨天的微信布局的基础上加内容 http://www.cnblogs.com/Seven-cjy/p/6098024.html

项目下/res/layout下创建一个 listview_layout.xml  的 xml 文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView> </LinearLayout>

listview_layout.xml

项目下/res/layout下创建一个 listview_item_layout.xml 的 xml 文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="horizontal" > <ImageView
android:id="@+id/imageView1"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="13dp"
android:layout_marginRight="13dp"
android:layout_marginTop="10dp"
android:src="@drawable/a" /> <LinearLayout
android:layout_width="wrap_content"
android:layout_height="70dp"
android:layout_weight="1"
android:orientation="vertical" > <TextView
android:id="@+id/tv_userName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:ellipsize="end"
android:singleLine="true"
android:textColor="@color/darkslategray"
android:textSize="16sp" /> <TextView
android:id="@+id/tv_lasMessage"
android:layout_width="match_parent"
android:layout_height="15dp"
android:layout_marginBottom="15dp"
android:layout_marginTop="8dp"
android:ellipsize="end"
android:gravity="bottom"
android:singleLine="true"
android:textColor="@color/gray"
android:textSize="11sp" />
</LinearLayout> <LinearLayout
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_marginLeft="10dp"
android:orientation="vertical" > <TextView
android:id="@+id/tv_datetime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:gravity="top"
android:textColor="@color/gray"
android:textSize="11sp" />
</LinearLayout> </LinearLayout>

listview_item_layout.xml

项目下 src 下 创建一个package的包  创建Message.java文件  (如:/项目/src/com/example/entity/Message.java)

package com.example.entity;

public class Message {
private String tou1;
private String userName;
private String lastMessage;
private String datetime; public String getTou1() {
return tou1;
} public void setTou1(String tou1) {
this.tou1 = tou1;
} public String getUserName() {
return userName;
} public void setUserName(String userName) {
this.userName = userName;
} public String getLastMessage() {
return lastMessage;
} public void setLastMessage(String lastMessage) {
this.lastMessage = lastMessage;
} public String getDatetime() {
return datetime;
} public void setDatetime(String datetime) {
this.datetime = datetime;
} }

Message.java

项目下 /src/com/example/winxinmff/MainActivity.java 文件

package com.example.winxinmff;

import java.util.ArrayList;
import java.util.List; import com.example.entity.Message; import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView; public class MainActivity extends Activity { private ListView lv;
private List<Message> messageList = new ArrayList<Message>(); protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.weixin); // 模拟读取数据库或者互联网
for (int i = 0; i < 20; i++) { // 模拟20条数据
Message p = new Message();
p.setTou1("xxx");
p.setUserName("不对外开放 高内聚 ");
p.setLastMessage("匿名内部类也就是没有名字的内部类匿名内部类也就是没有名字的内部类");
p.setDatetime("11.11");
messageList.add(p);
} lv = (ListView) findViewById(R.id.listView1);
// 简单理解为VC绑在一起
lv.setAdapter(new BaseAdapter() {
private View view; public int getCount() { // 返回多少条记录
return messageList.size();
} // 每一个item项, 返回一次界面
public View getView(int position, View convertView, ViewGroup parent) { // 布局不变,数据变 // 如果缓存为空 ,我们生成新的布局作为1个 item
if (convertView == null) {
Log.i("info: ", "没有缓存,重新生成" + position);
LayoutInflater inflater = MainActivity.this.getLayoutInflater(); // 因为 getView() 返回的对象, adapter 会自动赋给 List
view = inflater.inflate(R.layout.listview_item_layout, null);
} else {
Log.i("info: ", "有缓存,不需要重新生成" + position);
view = convertView;
} Message m = messageList.get(position); TextView tv_userName = (TextView) view.findViewById(R.id.tv_userName);
tv_userName.setText(m.getUserName() + position); TextView tv_lasMessage = (TextView) view.findViewById(R.id.tv_lasMessage);
tv_lasMessage.setText(m.getLastMessage()); TextView tv_datetime = (TextView) view.findViewById(R.id.tv_datetime);
tv_datetime.setText(m.getDatetime()); return view;
} public long getItemId(int position) {
return 0;
} public Object getItem(int position) {
return null;
}
}); } }

MainActivity.java

android 模拟微信消息框 BaseAdapter()方法 [2]的更多相关文章

  1. android 模拟微信消息 OnItemClickListener()方法 [3]

    在 http://www.cnblogs.com/Seven-cjy/p/6101555.html 是基础上修改 MainActivity.java /winxinmff/src/com/exampl ...

  2. WP&Win10仿微信消息框代码分享

    上次分享了幸运转盘的源码,感觉小伙伴们很喜欢:这次和大家分享下通信相关部分需要用到的类似微信的消息框代码,有需要的童鞋可以拿去用哟.自己尝试写的,可能有点low,勿喷呀! 希望以后有好的东西大家都分享 ...

  3. Android模拟微信主页面的Demo

    Android模拟微信主页面的Demo 效果图如下: 项目结构图如下: ContanctFragment: package com.demo.moniwexin; import android.app ...

  4. Android实例-消息框(XE8+小米2)

    方法一支持. 方法二与方法三都是三方单元,功能相同. 方法4与方法5报错,提示平台不支持. 第三方单元一: unit Android.JNI.Toast; // Java bridge class i ...

  5. 元素定位:selenium消息框处理 (alert、confirm、prompt)

    基础普及 alert对话框 .细分三种,Alert,prompt,confirm 1. alert() 弹出个提示框 (确定) 警告消息框 alert 方法有一个参数,即希望对用户显示的文本字符串.该 ...

  6. selenium 消息框元素定位处理

    以下内容来自于“风少”的博客 <元素定位:selenium消息框处理 (alert.confirm.prompt)> 基础普及 alert对话框 .细分三种,Alert,prompt,co ...

  7. 2.7.1 元素定位:selenium消息框处理 (alert、confirm、prompt)

    来源:http://blog.csdn.net/cui_angel/article/details/7784211        http://www.cnblogs.com/tobecrazy/p/ ...

  8. Android仿微信QQ等实现锁屏消息提醒

    demo代码如下: import android.content.Intent; import android.os.Bundle; import android.support.v7.app.App ...

  9. C#代码像QQ的右下角消息框一样,无论现在用户的焦点在哪个窗口,消息框弹出后都不影响焦点的变化,那么有两种方法

    你QQ的右下角消息框一样,无论现在用户的焦点在哪个窗口,消息框弹出后都不影响焦点的变化,那么有两种方法: 要么重写需要弹出的窗体的事件: protected override CreateParams ...

随机推荐

  1. The ToolStripMenuItem visible value always false

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/8cf60e57-6d97-43c6-bb3a-394b9bf130af/the-tools ...

  2. [Design Pattern] Flywight Pattern 简单案例

    Flywight Pattern, 即享元模式,用于减少对象的创建,降低内存的占用,属于结构类的设计模式.根据名字,我也将其会理解为 轻量模式. 下面是享元模式的一个简单案例. 享元模式,主要是重用已 ...

  3. 西装定制平台Indochino获$1350万B轮融资 - 国际B2C - 亿邦动力网

    西装定制平台Indochino获$1350万B轮融资 - 国际B2C - 亿邦动力网 西装定制平台Indochino获$1350万B轮融资 作者: 韦龑来源: i黑马网2013-03-29 11:05 ...

  4. Sublime text 3 格式化HTML/css/js/json代码 插件

    JsFormat: 这里下载这插件包 https://github.com/jdc0589/JsFormat ,点油下角的zip就能下载 插件包放到sublime安装目录的Data\Packages目 ...

  5. ECLIPSE/MYECLIPSE OPERATES

    Eclipse相关操作 1.删除所有注释 1.eclipse删除所有注释 Ctrl+F: /\*{1,2}[\s\S]*?\*/ 选择正则表达式,替换全部即可.

  6. 解决本地软件链接不上虚拟机mysql 的问题:grant all privileges on *.* to 'root'@'%' identified by 'nsfocus'

    mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' ->     IDENTIFIED BY 'some_pass' WITH ...

  7. Android控件Editext、TextView属性详解

    EditText属性描述 android:layout_gravity="center_vertical"//设置控件显示的位置:默认top,这里居中显示,还有bottom and ...

  8. 了解SVG

    页的节点类型,我们将说明怎样通过Illustrator高速的把SVG文档加入到网页中.我们还会讲讲D3.js,一个强大的.SVG控制的JavaScript库. "SVG并不仅仅用于像素处理. ...

  9. 灵活性比Listview更好的RecycleView

    RecycleView:是Android L版本中新添加的一个用来取代ListView的SDK,它的灵活性与可替代性比listview更好. RecyclerView与ListView原理是类似的:都 ...

  10. Linux popen/pclose

    popen() 函数 #include <stdio.h>FILE * popen(const char *command , const char *type );int pclose( ...