使用 ExpandableListView控件实现好友列表,登录后跳转到FriendActivity

修改friend_layout.xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"><com.example.androidlogin.TitleLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content" /><ExpandableListViewandroid:id="@id/android:list"android:layout_width="fill_parent"android:layout_height="fill_parent" /></LinearLayout>

layout文件夹下定义布局一级列表groups.xml

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><TextViewandroid:id="@+id/textGroup"android:layout_width="fill_parent"android:layout_height="fill_parent"android:paddingLeft="40px"android:paddingTop="6px"android:paddingBottom="6px"android:textSize="25sp"android:text="No data"/></LinearLayout>

layout文件夹下再定义布局二级列表childs.xml

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><TextViewandroid:id="@+id/textChild"android:layout_width="fill_parent"android:layout_height="fill_parent"android:paddingLeft="60px"android:paddingTop="10px"android:paddingBottom="10px"android:textSize="20sp"android:text="No Data"/></LinearLayout>

回到FriendActivity

import android.os.Bundle;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.os.Bundle;
import android.app.ExpandableListActivity;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.SimpleExpandableListAdapter;
import android.widget.Toast;public class FriendActivity extends ExpandableListActivity {/*** 创建一级条目容器*/List<Map<String, String>> gruops = new ArrayList<Map<String, String>>();/*** 存放内容, 以便显示在列表中*/List<List<Map<String, String>>> childs = new ArrayList<List<Map<String, String>>>();@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.friend_layout);setListData();}/*** 设置列表内容*/public void setListData() {// 创建二个一级条目标题Map<String, String> title_1 = new HashMap<String, String>();Map<String, String> title_2 = new HashMap<String, String>();Map<String, String> title_3 = new HashMap<String, String>();title_1.put("group", "我的好友");title_2.put("group", "我的同学");gruops.add(title_1);gruops.add(title_2);// 创建二级条目内容// 内容一Map<String, String> title_1_content_1 = new HashMap<String, String>();Map<String, String> title_1_content_2 = new HashMap<String, String>();Map<String, String> title_1_content_3 = new HashMap<String, String>();title_1_content_1.put("child", "张三");title_1_content_2.put("child", "李四");title_1_content_3.put("child", "王五");List<Map<String, String>> childs_1 = new ArrayList<Map<String, String>>();childs_1.add(title_1_content_1);childs_1.add(title_1_content_2);childs_1.add(title_1_content_3);// 内容二Map<String, String> title_2_content_1 = new HashMap<String, String>();Map<String, String> title_2_content_2 = new HashMap<String, String>();Map<String, String> title_2_content_3 = new HashMap<String, String>();title_2_content_1.put("child", "小明");title_2_content_2.put("child", "小红");title_2_content_3.put("child", "小绿");List<Map<String, String>> childs_2 = new ArrayList<Map<String, String>>();childs_2.add(title_2_content_1);childs_2.add(title_2_content_2);childs_2.add(title_2_content_3);childs.add(childs_1);childs.add(childs_2);/*** 创建ExpandableList的Adapter容器 参数: 1.上下文 2.一级集合 3.一级样式文件 4. 一级条目键值* 5.一级显示控件名 6. 二级集合 7. 二级样式 8.二级条目键值 9.二级显示控件名**/SimpleExpandableListAdapter sela = new SimpleExpandableListAdapter(this, gruops, R.layout.groups, new String[] { "group" },new int[] { R.id.textGroup }, childs, R.layout.childs,new String[] { "child" }, new int[] { R.id.textChild });// 加入列表setListAdapter(sela);}/*** 列表内容按下*/@Overridepublic boolean onChildClick(ExpandableListView parent, View v,int groupPosition, int childPosition, long id) {Toast.makeText(FriendActivity.this,"您选择了"+ gruops.get(groupPosition).toString()+ "子编号"+ childs.get(groupPosition).get(childPosition).toString(), Toast.LENGTH_SHORT).show();//跳转到聊天界面Intent intent = new Intent(FriendActivity.this,SuccessActivity.class);startActivity(intent);return super.onChildClick(parent, v, groupPosition, childPosition, id);}/*** 二级标题按下*/public boolean setSelectedChild(int groupPosition, int childPosition,boolean shouldExpandGroup) {return super.setSelectedChild(groupPosition, childPosition,shouldExpandGroup);}/*** 一级标题按下*/@Overridepublic void setSelectedGroup(int groupPosition) {super.setSelectedGroup(groupPosition);}
}

EChat(简易聊天项目)二、好友列表实现相关推荐

  1. EChat(简易聊天项目)七、保存聊天记录

    (二)使用LitePal数据库保存用户聊天记录 分析: 首先需要进行数据库的创建,需要一张表(自定义类HistoryChat)来保存聊天记录信息, 其次,需要将聊天的记录增加到数据库对应记录中:最后需 ...

  2. EChat(简易聊天项目)三、聊天界面UI实现

    一.添加部分控件完善登入过程 ① 设计应用登录界面加入ImageView 在login_layout.xml中加入以下代码 <?xml version="1.0" encod ...

  3. EChat(简易聊天项目)八、Socket实现即时通信(包括部分修改)

    利用Socket实现即时通信 在MyEclipse中写Server端 工程结构如图 SocketMessage.java 该类是一个消息类,用于表示消息是由谁发给谁的.消息内容是什么.接收时间是多少, ...

  4. EChat(简易聊天项目)五、存储聊天记录中的图片

    利用文件存储实现存储聊天记录中的图片 首先先需要使聊天界面可以发送图片,然后再对其进行存储操作 ①修改Msg类,增加了imgpath,即图片路径 public class Msg {public st ...

  5. EChat(简易聊天项目)四、模拟强制下线

    利用标准广播或本地广播模拟聊天应用中用户异地登录时的强制下线功能 ①修改IndexActivity中代码 public class IndexActivity extends BaseActivity ...

  6. EChat(简易聊天项目)六、实现记住密码和自动登录

    利用SharedPreferences登录界面记住密码和自动登录 ①修改login_layout.xml文件,增加如下代码,即添加2个勾选框 <LinearLayoutandroid:orien ...

  7. EChat(简易聊天项目)一、登录注册实现

    具体实现代码: ① 活动LoginActivity(负责登录界面) package com.example.androidlogin;import android.content.Intent; im ...

  8. Dobbo微服务项目实战(详细介绍+案例源码) - 5.推荐好友列表/MongoDB集群/动态发布与查看

    You are a wizard, Harry! 系列文章目录 1. 项目介绍及环境配置 2. 短信验证码登录 3. 用户信息 4. MongoDB 5.推荐好友列表/MongoDB集群/动态发布与查 ...

  9. 2020暑假集训项目——Java简易聊天室

    经过一周的学习与搬砖,我成功的完成了暑假集训的第一个项目--Java简易聊天室,这里对整个项目做一个总结.(文末附下载地址) 本项目支持的功能: 1.可同时开启多个客户端进行多人聊天: 2.可与在线的 ...

最新文章

  1. 深挖之后吓一跳,谷歌AI专利何止一个dropout,至少30项今日生效
  2. 印章WinForm自定义控件封装,提供源码下载
  3. win7 php mysql扩展名_win7下MySQL 5.1.73安装过程(图解)并在php.ini中启用相关扩展。...
  4. java k均值_算法——K均值聚類算法(Java實現)
  5. js向服务器发送信息,Angularjs向服务器发送请求
  6. 计算机网络技术通识试题,超星计算机网络技术章节答案
  7. objective-c block 旧版详解
  8. jdk12连接mysql_使用基于JDK12版本的JDBC读取数据库中的数据在网页(jsp)表示出来...
  9. Atitit 智能云网络摄像机的前世今生与历史 优点  密码默认888888
  10. 三菱plc编程电缆通讯端口设置方法(转载)
  11. vscode统计代码行数
  12. 二进制转换为十六进制数是_将二进制数制转换为十六进制数制
  13. 盘古搜索:上市是既定策略 寻求股权多元化
  14. c语言人民日报排版的代码,人民日报都在玩的排版黑科技,教你1分钟上手!
  15. 4246. 【五校联考6day2】san (Standard IO)
  16. 遇人不淑之逗比程序员
  17. 大写日期(大写日期10月前要写0吗)
  18. 有n个结构体变量,内含学生学号、姓名和3门课程的成绩。要求输出平均成绩最高的学生的信息(包括学号、姓名、3门课程成绩和平均成绩)
  19. word文档找不到smartart_Word2007新工具“SmartArt”使用教程
  20. 盗版免费升级到Win10仍是盗版 官方不保证稳定性

热门文章

  1. 组合数学(4)——拉丁方矩阵
  2. 《Web前端工程师修炼之道》学习笔记
  3. 基于STM32F1实现秒表及万年历功能【寄存器版】
  4. win7如何修改html图标,win7如何更改软件图标_win7修改应用程序图标的教程
  5. 机器翻译古文也翻车?读了20次“苟富贵勿相忘”后,谷歌:没钱的人总会被遗忘...
  6. 基于区域生长的图像分割算法!
  7. Connecting to 192.168.237.129:22... Could not connect to '192.168.237.129' (port 22): Connection fai
  8. 浅谈大数据平台架构设计
  9. u盘插在电脑上没有反应_电脑无法识别U盘或插上U盘提示格式化
  10. 十五万左右纯电SUV怎么选?奇瑞大蚂蚁是真香