QQ 添加分组 添加好友
来源:互联网 发布:php 上传中文文件名 编辑:程序博客网 时间:2024/04/30 07:10
package com.example.qq;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Random;import android.app.Activity;import android.content.Context;import android.graphics.Color;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.Button;import android.widget.ExpandableListAdapter;import android.widget.ExpandableListView;import android.widget.ExpandableListView.OnGroupClickListener;import android.widget.SimpleExpandableListAdapter;import android.widget.TextView;public class MainActivity extends Activity {private final String GROUP = "group";private final String CHILD = "child";private ArrayList<HashMap<String, Object>> data;private MyExpandableListAdapter mExpandableListAdapter;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);// 分组的标签String[] g = { "时光机", "好久不见", "黑色幽默", "甜甜的", "说好的幸福呢" };data = new ArrayList<HashMap<String, Object>>();// 子数据的计数//int COUNT = 0;//Random rand = new Random();for (int i = 0; i < g.length; i++) {HashMap<String, Object> map = new HashMap<String, Object>();map.put(GROUP, g[i]);ArrayList<String> child = new ArrayList<String>();//int k = rand.nextInt(10);// 为每个子List随机生成k个测试数据for (int j = 0; j < 5; j++) {child.add("朋友" + j);}map.put(CHILD, child);data.add(map);}ExpandableListView elv = (ExpandableListView) findViewById(R.id.expandableListView);elv.setGroupIndicator(null);// 这是一个参数为空或者null的ExpandableListAdapter// 构造在子类中完成mExpandableListAdapter = new MyExpandableListAdapter(this, null, 0, null, null, null, 0, null, null);elv.setAdapter(mExpandableListAdapter);// 展开0组//elv.expandGroup(0);// 展开1组//elv.expandGroup(1);// 展开2组//elv.expandGroup(2);elv.setOnGroupClickListener(new OnGroupClickListener() {@Overridepublic boolean onGroupClick(ExpandableListView arg0, View arg1,int arg2, long arg3) {// Android默认是返回false。// 如果返回true,那么,不管是点击已展开的分组还是未展开的分组,都不会相应展开或者收缩的,也就是说这个ExpandableListView将成为一个‘死’的ListViewreturn false;}});Button button1 = (Button) findViewById(R.id.button1);button1.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View arg0) {addGroupData(2);}});Button button2 = (Button) findViewById(R.id.button2);button2.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {addChildData(1,"3");}});}private void addChildData(int pos,String str) {HashMap<String,Object> map = data.get(pos);ArrayList<String> list = (ArrayList<String>)map.get(CHILD);list.add(2,str);mExpandableListAdapter.notifyDataSetChanged();}private void addGroupData(int pos) {HashMap<String,Object> map = new HashMap<String,Object>();map.put(GROUP,"听妈妈的话");ArrayList<String> child = new ArrayList<String>();for(int j=0;j<5;j++){child.add("朋友"+j);}map.put(CHILD,child);//data.add(map);data.add(pos,map);mExpandableListAdapter.notifyDataSetChanged();}private class MyExpandableListAdapter extends SimpleExpandableListAdapter {private LayoutInflater inflater;public MyExpandableListAdapter(Context context,List<? extends Map<String, ?>> groupData, int groupLayout,String[] groupFrom, int[] groupTo,List<? extends List<? extends Map<String, ?>>> childData,int childLayout, String[] childFrom, int[] childTo) {super(context, groupData, groupLayout, groupFrom, groupTo,childData, childLayout, childFrom, childTo);inflater = LayoutInflater.from(context);}@Overridepublic Object getChild(int groupPosition, int childPosition) {ArrayList<String> items = (ArrayList<String>) data.get(groupPosition).get(CHILD);return items.get(childPosition);}@Overridepublic View getChildView(int groupPosition, int childPosition,boolean isLastChild, View convertView, ViewGroup parent) {View view = inflater.inflate(android.R.layout.simple_list_item_1,null);TextView text = (TextView) view.findViewById(android.R.id.text1);text.setText(getChild(groupPosition, childPosition) + "");return view;}@Overridepublic int getChildrenCount(int groupPosition) {ArrayList<String> items = (ArrayList<String>) data.get(groupPosition).get(CHILD);return items.size();}@Overridepublic Object getGroup(int groupPosition) {return data.get(groupPosition).get(GROUP);}@Overridepublic int getGroupCount() {return data.size();}@Overridepublic View getGroupView(int groupPosition, boolean isExpanded,View convertView, ViewGroup parent) {View view = inflater.inflate(android.R.layout.simple_list_item_1,null);TextView text = (TextView) view.findViewById(android.R.id.text1);text.setText(getGroup(groupPosition) + "");view.setBackgroundColor(Color.RED);return view;}}}
<LinearLayout 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" android:orientation="vertical" tools:context="com.example.qq.MainActivity" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="添加分组" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="添加朋友" /></LinearLayout> <ExpandableListView android:id="@+id/expandableListView" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout>
0 0
- QQ 添加分组 添加好友
- QQ好友分组添加好友(UITableView实现)
- 添加qq好友
- openfire--好友管理实现好友添加及分组管理
- openfire-好友管理实现好友添加及分组管理
- Android 基于xmpp协议,smack包,openfire服务端的高仿QQ的即时通讯实现【3】添加分组,添加好友,读取好友列表的实现
- 添加qq好友 msn的显示
- 生成QQ在线状态 无需添加好友
- QQ临时聊天,无须添加好友
- 营销QQ添加好友限制完美解决方案
- CSDN博客添加加QQ好友按钮
- CSDN博客添加QQ好友按钮
- 添加好友
- Android app内部启动qq/跳转到QQ添加好友
- 类似QQ好友分组栏
- 在线qq需要添加好友才能聊天的解决方法
- ★营销QQ辅助软件如何迅速添加好友★
- ★营销QQ辅助软件如何迅速添加好友★
- MongoDB小结14 - find【查询条件$lt $lte $gt $gte】
- 背包九讲
- hdu 1053 哈夫曼树 优先队列
- javascript与Jquery整理
- 卷积神经网络CNN
- QQ 添加分组 添加好友
- 数据库课程设计开发笔记(一)
- BZOJ 2115 Xor(dfs&独立回路&异或消元)
- HDOJ 5563 Clarke and five-pointed star (判断五个点组成的是否为正五角星)
- Appium Wrapper for Java
- 下一代分布式消息系统:Apache Kafka
- Apache Cordova介绍
- [HDU 1811]Rank of Tetris[拓扑排序][并查集]
- ffmpeg time_base