ArrayAdapter适配器的用法,模拟QQ发消息界面。

 1 import java.util.ArrayList;
 2
 3 import android.app.Activity;
 4 import android.content.Context;
 5 import android.os.Bundle;
 6 import android.view.LayoutInflater;
 7 import android.view.View;
 8 import android.view.View.OnClickListener;
 9 import android.view.ViewGroup;
10 import android.widget.ArrayAdapter;
11 import android.widget.Button;
12 import android.widget.EditText;
13 import android.widget.ListView;
14 import android.widget.TextView;
15
16 public class MainActivity extends Activity {
17     EditText et;
18     Button btn;
19     ListView lv;
20     MyAdapter mMyAdapter;
21     ArrayList<String> date;
22
23     @Override
24     protected void onCreate(Bundle savedInstanceState) {
25         super.onCreate(savedInstanceState);
26         setContentView(R.layout.activity_main);
27
28         date = new ArrayList<String>();
29         et = (EditText) findViewById(R.id.et1);
30         btn = (Button) findViewById(R.id.btn1);
31         lv = (ListView) findViewById(R.id.lv);
32
33         mMyAdapter = new MyAdapter(this, R.layout.list);
34         // 设置ListView的适配器 (ArrayAdapter适配器的用法)
35         lv.setAdapter(mMyAdapter);
36
37         btn.setOnClickListener(new OnClickListener() {
38
39             @Override
40             public void onClick(View v) {
41                 sendmessage();
42             }
43         });
44     }
45
46     public void sendmessage() {
47         date.add(et.getText().toString());
48         mMyAdapter.notifyDataSetChanged();
49         // 发送完设置输入框为空
50         et.setText(null);
51         // 发送消息后将ListView滚动到最下方
52         lv.setSelection(ListView.FOCUS_DOWN);
53     }
54
55     public class MyAdapter extends ArrayAdapter {
56         private Context context;
57         private int resource;
58
59         public MyAdapter(Context context, int resource) {
60             super(context, resource);
61             this.resource = resource;
62             this.context = context;
63         }
64
65         @Override
66         public int getCount() {
67
68             return date.size();
69         }
70
71         @Override
72         public View getView(int position, View convertView, ViewGroup parent) {
73
74             LayoutInflater flater = LayoutInflater.from(context);
75             // 设置可以复用view
76             if (convertView == null) {
77                 convertView = flater.inflate(resource, null);
78             }
79             TextView tv = (TextView) convertView.findViewById(R.id.qqtxt);
80             tv.setText(date.get(position));
81
82             return convertView;
83         }
84
85     }
86 }

xml文件:

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:id="@+id/RelativeLayout1"
 4     android:layout_width="match_parent"
 5     android:layout_height="match_parent" >
 6
 7     <ImageView
 8         android:id="@+id/ImageView1"
 9         android:layout_width="50dp"
10         android:layout_height="50dp"
11         android:layout_alignParentRight="true"
12         android:layout_centerVertical="true"
13         android:background="@drawable/meimei" />
14
15     <TextView
16         android:id="@+id/qqtxt"
17         android:layout_width="wrap_content"
18         android:layout_height="wrap_content"
19         android:layout_centerVertical="true"
20         android:layout_toLeftOf="@+id/ImageView1"
21         android:background="#ff5252"
22         android:text="1233"
23         android:textSize="20sp" />
24
25 </RelativeLayout>
 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     xmlns:tools="http://schemas.android.com/tools"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     tools:context="com.lixu.qqduihua.MainActivity" >
 6
 7     <ListView
 8         android:id="@+id/lv"
 9         android:layout_width="match_parent"
10         android:layout_height="wrap_content"
11         android:layout_above="@+id/commentLinearLayout"
12         android:layout_alignParentTop="true"
13         android:divider="@android:color/transparent"
14         android:dividerHeight="15dip"
15         android:scrollbars="none" />
16
17     <LinearLayout
18         android:id="@+id/commentLinearLayout"
19         android:layout_width="match_parent"
20         android:layout_height="wrap_content"
21         android:layout_alignParentBottom="true"
22         android:background="#e0e0e0"
23         android:orientation="horizontal" >
24
25         <EditText
26             android:id="@+id/et1"
27             android:layout_width="wrap_content"
28             android:layout_height="wrap_content"
29             android:layout_weight="2"
30             android:ems="10"
31             android:hint="请输入内容" >
32
33             <requestFocus />
34         </EditText>
35
36         <Button
37             android:id="@+id/btn1"
38             android:layout_width="wrap_content"
39             android:layout_height="wrap_content"
40             android:background="@drawable/round"
41             android:text="发送" />
42     </LinearLayout>
43
44 </RelativeLayout>
时间: 2024-08-08 01:26:23

ArrayAdapter适配器的用法,模拟QQ发消息界面。的相关文章

vbs脚本实现qq定时发消息(初级)

vbs脚本实现QQ消息定时发送 目标 批处理又称为批处理脚本,强大的强大功能可以高效得实现很多功能,例如批量更改文件格式,批量进行文件读写,今天我们的目标是用vbs脚本编写可以发送qq消息的脚本,并利用c++程序,实现qq消息的定时自动发送 准备 记事本 vbs脚本不需要什么花里花哨的东西,记事本足矣 c++编译器 随便选一个就行 开工 编写vbs脚本 VBS是基于Visual Basic的脚本语言,功能还是很强的,当然我也只会一点点皮毛,因为工作需要,去学习了如何写发送QQ消息的脚本~ 新建一

【VC编程技巧】窗体?3.7托盘程序介绍(模拟QQ消息)

所谓的托盘程序就是运行时在系统托盘区(就是桌面右下角显示时间的区域)出现一个小图标的程序.代表它运行的图标称作托盘图标.我们可以通过使用小图标来控制应用程序的状态. (一)NOTIFYICONDATA Structure typedef struct _NOTIFYICONDATA { DWORDcbSize;//结构体大小 HWNDhWnd;//接受icon消息的窗口句柄 UINT uID;//icon图标的资源Id UINTuFlags;//标志一些成员是否有效 UINTuCallbackM

仿QQ电话/消息切换的自定义布局结合Fragment解决你的需求!

转载请注明出处:王亟亟的大牛之路 先上模仿的对象:QQ的电话/消息 界面 用户点击消息或者电话会切换不同的界面 然后再上自己实现的界面 然后再附带了一些每一个Fragment内部的操作,来模拟切换后的效果 实现方法: 一个自定义控件+下面的Fragment.利用setOnSegmentControlViewClickListener方法来监听用户的点击来对界面进行操作. 项目目录结构 一个主Activity加一系列分页的Fragment(其实这里可以用Java代码来添加Fragment,但是考虑

关于 使用python向qq好友发送消息(对爬虫的作用----当程序执行完毕或者报错无限给自己qq发送消息,直到关闭)

以前看到网上一些小程序,在处理完事物后会自动发送qq消息,但是一直搞不懂是说明原理.也在网上找过一些python登陆qq发送消息的文字,但是都太复杂了.今天偶然看到一篇文章,是用python调用win32的接口发送qq消息的,觉得不错,就先记录下来,日后肯定会用得上这些小工具. 发送qq消息要求已经登陆qq,而且qq的窗口是独立的,现在新版的qq一般都是将所有的聊天窗口聚合在一起,因此要设置将qq窗口分离,或者将需要发送消息的那个窗口单独分离出来. 上代码吧. # 原理是先将需要发送的文本放到剪

通过程序调用微信公众号发消息api返回48001

自己的订阅号,尝试通过写程序来给用户发消息.结果呢,接口返回报错:errcode=48001,errmsg = api unauthorized hint: [ZlPULa02942276!] 去微信开发者文档官网查询返回码,说48001表示api未授权. 于是,微信公众平台->开发->接口权限,果真,群发消息接口提示“未获得” 那么,怎么获得呢?得通过微信认证.你妹呀,认证时发现,微信竟然对个人主体关闭了认证功能. ------------我是么么哒分割线---------------- 我

模拟QQ系统设置面板实现功能

业务需求: 基于网盘客户端的实现,原有网盘的设置面板无论从界面显示还是从业务需求都不能满足我们的正常需求.当前的要求是,模拟QQ系统设置的面板实现当前我们网盘中的基本配置功能.在完成这篇文章时已将基本功能实现完成,虽未整合进网盘客户端中,但基本技术预演已经实现. QQ系统设置面板分析: QQ系统设置面板效果图: QQ系统设置面板功能描述: 由于存在较多的配置,如果每个模块的配置项都设计到一个窗体中,则会存在很多的窗体,不太符合用户的使用体验,且程序编写也比较麻烦.QQ系统设置面板中的实现是,所有

【大话QT之八】模拟QQ系统设置面板实现功能

业务需求: 基于网盘客户端的实现,原有网盘的设置面板无论从界面显示还是从业务需求都不能满足我们的正常需求.当前的要求是,模拟QQ系统设置的面板实现当前我们网盘中的基本配置功能.在完成这篇文章时已将基本功能实现完成,虽未整合进网盘客户端中,但基本技术预演已经实现. QQ系统设置面板分析: QQ系统设置面板效果图: QQ系统设置面板功能描述: 由于存在较多的配置,如果每个模块的配置项都设计到一个窗体中,则会存在很多的窗体,不太符合用户的使用体验,且程序编写也比较麻烦.QQ系统设置面板中的实现是,所有

Winform调用QQ发信息并且开机启动 (开源)

前言 公司CS系统需要加入启动qq从winform调用qq聊天窗口的功能,前提是需要将聊天者的QQ号码作为参数传递到函数中,一直没有搞过,正好很感兴趣,就折腾,Winform调用qq,我想肯定是需要一些编码思路,下面列出编码前思路图 检查QQ安装后在注册表中的具体路径 根据注册表找到调用QQ程序的exe完整路径(Timwp.exe) 启动,达到winform调用QQ的要求 先看简单测试界面 步骤1 找到QQ的注册表路径,经过百度之后分析得到思路,正确的路径 32位QQ安装后注册表路径SOFTWA

利用phantomjs模拟QQ自动登录

之前为了抓取兴趣部落里的数据,研究了下QQ自动登录. 当时搜索了一番,发现大部分方法都已经失效了,于是准备自己开搞. 第一个想到的就是参考网上已有方案的做法,梳理登陆js的实现,通过其他语言重写.考虑到js可能会更新,放弃了此方案. 第二个想到的是能不能直接调用QQ自己的js方法,模拟进行提交呢.搜索一番后发现神器 ---- "phantomjs". PhantomJS is a headless WebKit scriptable with a JavaScript API. It