qq_34670769 2016-05-30 14:57 采纳率: 100%
浏览 2302

android expandablelistview二级目录点击跳转另一个activity

比如点击“妹妹”跳转一个新的聊天界面package com.czu.chat;

import android.app.ExpandableListActivity;

import android.content.Context;

import android.content.Intent;

import android.os.Bundle;

import android.os.Handler;

import android.os.Message;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.widget.BaseExpandableListAdapter;

import android.widget.Button;

import android.widget.ExpandableListView;

import android.widget.LinearLayout;

import android.widget.SimpleExpandableListAdapter;

import android.widget.TextView;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

/**

  • Created by 布丁 on 2016/5/30.

    /

    public class ExpandActivity extends ExpandableListActivity {

    /
    * Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.two);

    //创建二个一级条目标题                                                                                         
    Map<String, String> title_1 = new HashMap<String, String>();                                         
    Map<String, String> title_2 = new HashMap<String, String>();                                         
    
    title_1.put("group", "家人");                                                                          
    title_2.put("group", "宠物");                                                                          
    
    //创建一级条目容器                                                                                           
    List<Map<String, String>> gruops = new ArrayList<Map<String, String>>();                             
    
    gruops.add(title_1);                                                                                 
    gruops.add(title_2);                                                                                 
    
    //创建二级条目内容                                                                                           
    
    //内容一                                                                                                
    Map<String, String> content_1 = new HashMap<String, String>();                                       
    Map<String, String> content_2 = new HashMap<String, String>();                                       
    
    content_1.put("child", "姐姐");                                                                        
    content_2.put("child", "妹妹");                                                                        
    
    List<Map<String, String>> childs_1 = new ArrayList<Map<String, String>>();                           
    childs_1.add(content_1);                                                                             
    childs_1.add(content_2);                                                                             
    
    //内容二                                                                                                
    Map<String, String> content_3 = new HashMap<String, String>();                                       
    Map<String, String> content_4 = new HashMap<String, String>();                                       
    
    content_3.put("child", "猫咪");                                                                        
    content_4.put("child", "汪汪");                                                                        
    
    List<Map<String, String>> childs_2 = new ArrayList<Map<String, String>>();                           
    childs_2.add(content_3);                                                                             
    childs_2.add(content_4);                                                                             
    
    //存放两个内容, 以便显示在列表中                                                                                   
    List<List<Map<String, String>>> childs = new ArrayList<List<Map<String, String>>>();                 
    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);                                                                                
    

    }

  • 写回答

4条回答

  • devmiao 2016-05-30 15:04
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用