最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android仿QQ分組實(shí)現(xiàn)二級菜單展示

 更新時(shí)間:2019年09月08日 16:30:14   作者:Philtell  
這篇文章主要為大家詳細(xì)介紹了Android仿QQ分組實(shí)現(xiàn)二級菜單展示,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android仿QQ分組實(shí)現(xiàn)二級菜單展示的具體代碼,供大家參考,具體內(nèi)容如下

首先展示下要實(shí)現(xiàn)的效果

動態(tài)查看請看鏈接

1.首先要定義item,也就是二級展示的item

child_item.xml

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

 <com.makeramen.roundedimageview.RoundedImageView xmlns:app="http://schemas.android.com/apk/res-auto"
 android:id="@+id/iv"
 android:layout_width="60dp"
 android:layout_height="60dp"
 android:gravity="center_horizontal"
 android:src="#000000"
 app:riv_border_color="#333333"
 app:riv_border_width="3dip"
 app:riv_corner_radius="10dip"
 app:riv_mutate_background="true"
 app:riv_oval="true" />

 <LinearLayout
 android:layout_width="match_parent"
 android:layout_height="60dp"
 android:layout_toRightOf="@id/iv"
 android:orientation="vertical">

 <TextView
  android:id="@+id/friendname"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_weight="1"
  android:text="好友1"
  android:textColor="#000000"
  android:textSize="30dp" />

 <TextView
  android:id="@+id/motto"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_weight="1"
  android:text="這是好友1的簽名"
  android:textColor="#000000"
  android:textSize="20dp" />

 </LinearLayout>
</RelativeLayout>

效果如下圖所示:

2. 其次,設(shè)置分組item

groupitem.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_marginBottom="10dp">

 <ImageView
 android:id="@+id/triangle_right"
 android:layout_width="20dp"
 android:layout_height="40dp"
 android:layout_alignParentLeft="true"
 android:background="@drawable/triangle_right" />

 <TextView
 android:id="@+id/headtext"
 android:layout_width="match_parent"
 android:layout_height="40dp"
 android:layout_toLeftOf="@+id/online_people_num"
 android:layout_toRightOf="@+id/triangle_right"
 android:background="#E9E9E9"
 android:text="我的好友"
 android:textSize="25dp" />

 <TextView
 android:id="@+id/online_people_num"
 android:layout_width="60dp"
 android:layout_height="40dp"
 android:layout_alignParentRight="true"
 android:layout_marginRight="10dp"
 android:gravity="center_horizontal|center_vertical"
 android:text="0/15"
 android:textColor="#000000" />
</RelativeLayout>

效果下圖所示:

3. 創(chuàng)建相應(yīng)的數(shù)據(jù)對象

添加分組父菜單Group

Group.class

package com.example.m1.QQGroup;

public class Group {
 private int mGroupImage;
 private String mGroupName; //分組名
 private String mGroupNum; //分組人數(shù)
 private boolean isDown;

 public Group(int mGroupImage, String mGroupName, String mGroupNum) {
 this.mGroupImage = mGroupImage;
 this.mGroupName = mGroupName;
 this.mGroupNum = mGroupNum;
 }

 public Group() {
 this.isDown = false;
 }

 public void changeDownStatus(){
 isDown = !isDown;
 }

 public boolean isDown() {
 return isDown;
 }

 public void setDown(boolean down) {
 isDown = down;
 }

 public int getmGroupImage() {
 return mGroupImage;
 }

 public void setmGroupImage(int mGroupImage) {
 this.mGroupImage = mGroupImage;
 }

 public String getmGroupName() {
 return mGroupName;
 }

 public void setmGroupName(String mGroupName) {
 this.mGroupName = mGroupName;
 }

 public String getmGroupNum() {
 return mGroupNum;
 }

 public void setmGroupNum(String mGroupNum) {
 this.mGroupNum = mGroupNum;
 }
}

4. 添加子菜單Item

Item.class

package com.example.m1.QQGroup;

public class Item {
 private String mName;//人名
 private String mMotto; //簽名
 private int mPhoto; //頭像

 public Item() {

 }

 public Item(String mName, String mMotto) {
 this.mName = mName;
 this.mMotto = mMotto;

 }

 public Item(String mName, String mMotto, int mPhoto) {
 this.mName = mName;
 this.mMotto = mMotto;
 this.mPhoto = mPhoto;
 }

 public String getmName() {
 return mName;
 }

 public void setmName(String mName) {
 this.mName = mName;
 }

 public String getmMotto() {
 return mMotto;
 }

 public void setmMotto(String mMotto) {
 this.mMotto = mMotto;
 }

 public int getmPhoto() {
 return mPhoto;
 }

 public void setmPhoto(int mPhoto) {
 this.mPhoto = mPhoto;
 }
}

5. 添加適配器

MyBaseExpandableListAdapter.class

package com.example.m1.QQGroup;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.m1.R;

import java.util.ArrayList;

public class MyBaseExpandableListAdapter extends BaseExpandableListAdapter {

 private ArrayList<Group> gData; //分組
 private ArrayList<ArrayList<Item>> iData; //長鏈表
 private Context mContext;

 public MyBaseExpandableListAdapter(ArrayList<Group> gData, ArrayList<ArrayList<Item>> iData, Context mContext) {
 this.gData = gData;
 this.iData = iData;
 this.mContext = mContext;
 }

 @Override
 public int getGroupCount() {
 return gData.size();
 }

 @Override
 public int getChildrenCount(int i) {
 return iData.get(i).size();
 }

 @Override
 public Object getGroup(int i) {
 return gData.get(i);
 }

 @Override
 public Object getChild(int i, int i1) {
 return iData.get(i).get(i1);
 }

 @Override
 public long getGroupId(int i) {
 return i;
 }

 @Override
 public long getChildId(int i, int i1) {
 return i1;
 }

 @Override
 public boolean hasStableIds() {
 return false;
 }

 /**
 * 取得用于顯示給定分組的視圖,這個方法僅返回分組的試圖對象
 * @param i
 * @param b
 * @param view
 * @param viewGroup
 * @return
 */
 @Override
 public View getGroupView(final int i, boolean b, View view, final ViewGroup viewGroup) {
 final ViewHolderGroup groupHolder;
 if (view == null){
  view = LayoutInflater.from(mContext).inflate(R.layout.groupitem,viewGroup,false);
  groupHolder = new ViewHolderGroup();
  groupHolder.mGroupImage = view.findViewById(R.id.triangle_right);
  groupHolder.mGroupName = view.findViewById(R.id.headtext);
  groupHolder.mGroupNum = view.findViewById(R.id.online_people_num);
  view.setTag(groupHolder);
 }else{
  groupHolder = (ViewHolderGroup) view.getTag();
 }
 //groupHolder.mGroupImage.setImageResource(gData.get(i).getmGroupImage());
 Log.d("gData",gData.get(i).getmGroupImage()+"");
 Log.d("gData",gData.get(i).getmGroupName()+"");
 groupHolder.mGroupName.setText(gData.get(i).getmGroupName());
 groupHolder.mGroupNum.setText(gData.get(i).getmGroupNum());

 return view;
 }

 @Override
 public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
 ViewHolderItem itemHolder;
 if (view == null){
  view = LayoutInflater.from(mContext).inflate(R.layout.child_item,viewGroup,false);
  itemHolder = new ViewHolderItem();
  itemHolder.mPhoto = view.findViewById(R.id.iv);
  itemHolder.mMotto = view.findViewById(R.id.motto);
  itemHolder.mName = view.findViewById(R.id.friendname);
  view.setTag(itemHolder);
 }else{
  itemHolder = (ViewHolderItem) view.getTag();
 }

 itemHolder.mPhoto.setImageResource(iData.get(i).get(i1).getmPhoto());
 itemHolder.mName.setText(iData.get(i).get(i1).getmName());
 itemHolder.mMotto.setText(iData.get(i).get(i1).getmMotto());
 return view;
 }

 /**
 * 設(shè)置子列表是否可以選中
 * @param i
 * @param i1
 * @return
 */
 @Override
 public boolean isChildSelectable(int i, int i1) {
 return true;
 }

 private static class ViewHolderGroup{
 private ImageView mGroupImage;
 private TextView mGroupName; //分組名
 private TextView mGroupNum; //分組人數(shù)
 private boolean isDown;

 public ViewHolderGroup() {
  isDown = false;
 }
 }
 private static class ViewHolderItem{
 private TextView mName;//人名
 private TextView mMotto; //簽名
 private ImageView mPhoto; //頭像
 }
}

6. Main5Activity中填充數(shù)據(jù)

Main5Activity.class

package com.example.m1.QQGroup;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.Toast;

import com.example.m1.R;

import java.util.ArrayList;

public class Main5Activity extends AppCompatActivity {

 private ArrayList<Group> gData = null; //存儲所有的分組信息
 private ArrayList<ArrayList<Item>> iData = null; //每個分組的子信息
 private ArrayList<Item> lData = null;
 private Context mContext;
 private ExpandableListView mQQlist;
 private MyBaseExpandableListAdapter myAdapter = null;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main5);
 mContext = Main5Activity.this;
 mQQlist = findViewById(R.id.QQList);
 //數(shù)據(jù)準(zhǔn)備
 gData = new ArrayList<Group>();
 iData = new ArrayList<ArrayList<Item>>();
 gData.add(new Group(R.drawable.triangle_right,"小學(xué)同學(xué)","1/7"));
 gData.add(new Group(R.drawable.triangle_right,"初中同學(xué)","2/7"));
 gData.add(new Group(R.drawable.triangle_down,"高中同學(xué)","3/7"));
 gData.add(new Group(R.drawable.triangle_right,"大學(xué)同學(xué)","4/7"));

 lData =new ArrayList<Item>();

 //小學(xué)組
 lData.add(new Item("朋友1","有志者事竟成",R.drawable.f015));
 lData.add(new Item("朋友2","有志者事竟成",R.drawable.f015));
 lData.add(new Item("朋友3","有志者事竟成",R.drawable.f015));
 lData.add(new Item("朋友4","有志者事竟成",R.drawable.f040));
 lData.add(new Item("朋友5","有志者事竟成",R.drawable.f015));
 lData.add(new Item("朋友6","有志者事竟成",R.drawable.f015));
 lData.add(new Item("朋友7","有志者事竟成",R.drawable.f040));
 iData.add(lData);
 //初中組
 lData =new ArrayList<Item>();
 lData.add(new Item("朋友1","我愛你,不是說說而已",R.drawable.f015));
 lData.add(new Item("朋友2","我愛你,不是說說而已",R.drawable.f015));
 lData.add(new Item("朋友3","我愛你,不是說說而已",R.drawable.f040));
 lData.add(new Item("朋友4","我愛你,不是說說而已",R.drawable.f015));
 lData.add(new Item("朋友5","我愛你,不是說說而已",R.drawable.f040));
 lData.add(new Item("朋友6","我愛你,不是說說而已",R.drawable.f015));
 lData.add(new Item("朋友7","我愛你,不是說說而已",R.drawable.f040));
 iData.add(lData);
 //高中組
 lData =new ArrayList<Item>();
 lData.add(new Item("朋友1","為賦新詞強(qiáng)說愁",R.drawable.f015));
 lData.add(new Item("朋友2","為賦新詞強(qiáng)說愁",R.drawable.f040));
 lData.add(new Item("朋友3","為賦新詞強(qiáng)說愁",R.drawable.f015));
 lData.add(new Item("朋友4","為賦新詞強(qiáng)說愁",R.drawable.f040));
 lData.add(new Item("朋友5","為賦新詞強(qiáng)說愁",R.drawable.f015));
 lData.add(new Item("朋友6","為賦新詞強(qiáng)說愁",R.drawable.f040));
 lData.add(new Item("朋友7","為賦新詞強(qiáng)說愁",R.drawable.f015));
 iData.add(lData);
 //大學(xué)組
 lData =new ArrayList<Item>();
 lData.add(new Item("朋友1","I love you ",R.drawable.f015));
 lData.add(new Item("朋友2","I love you ",R.drawable.f015));
 lData.add(new Item("朋友3","I love you ",R.drawable.f040));
 lData.add(new Item("朋友4","I love you ",R.drawable.f015));
 lData.add(new Item("朋友5","I love you ",R.drawable.f040));
 lData.add(new Item("朋友6","I love you ",R.drawable.f015));
 lData.add(new Item("朋友7","I love you ",R.drawable.f015));
 iData.add(lData);
 myAdapter = new MyBaseExpandableListAdapter(gData,iData,mContext);
 mQQlist.setAdapter(myAdapter);

 mQQlist.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
  @Override
  public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
  Toast.makeText(mContext, "你點(diǎn)擊了:" + iData.get(groupPosition).get(childPosition).getmName(), Toast.LENGTH_SHORT).show();
  return true;
  }
 });

 }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android Jni的簡單使用詳解

    Android Jni的簡單使用詳解

    這篇文章主要介紹了Android Jni的簡單使用詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-02-02
  • Android實(shí)現(xiàn)淘寶客戶端倒計(jì)時(shí)界面

    Android實(shí)現(xiàn)淘寶客戶端倒計(jì)時(shí)界面

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)淘寶客戶端倒計(jì)時(shí)界面,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • Android控件ListView用法(讀取聯(lián)系人示例代碼)

    Android控件ListView用法(讀取聯(lián)系人示例代碼)

    本文以一個讀取聯(lián)系人的代碼為大家講解下Android控件中ListView的使用方法,這個listView有個setAdapter 適配器,里面可以直接實(shí)現(xiàn)接口,或者寫個類
    2013-06-06
  • Android開發(fā)中日期工具類DateUtil完整實(shí)例

    Android開發(fā)中日期工具類DateUtil完整實(shí)例

    這篇文章主要介紹了Android開發(fā)中日期工具類DateUtil,結(jié)合完整實(shí)例形式分析了Android針對日期與時(shí)間的計(jì)算、轉(zhuǎn)換、格式化、獲取等相關(guān)操作技巧,需要的朋友可以參考下
    2017-11-11
  • 詳解Andorid開發(fā)中反射機(jī)制是怎么一回事

    詳解Andorid開發(fā)中反射機(jī)制是怎么一回事

    反射機(jī)制是在運(yùn)行狀態(tài)中,對于任何一個類,都可以知道這個類的所有屬性和方法,對于任何一個對象,都可以調(diào)用它所有的方法和屬性,修改部分類型信息,這種動態(tài)獲取信息以及動態(tài)調(diào)用對象方法的功能稱為Java的反射機(jī)制
    2022-11-11
  • android自定義控件創(chuàng)建翻頁接口詳細(xì)代碼

    android自定義控件創(chuàng)建翻頁接口詳細(xì)代碼

    這篇文章主要為大家介紹了android自定義控件創(chuàng)建翻頁接口詳細(xì)代碼,具有一定的實(shí)用性,感興趣的小伙伴們可以參考一下
    2016-07-07
  • Android仿微信群聊頭像

    Android仿微信群聊頭像

    這篇文章主要為大家介紹了Android仿微信群聊頭像的相關(guān)資料,感興趣的小伙伴們可以參考一下
    2016-01-01
  • Android實(shí)現(xiàn)倒計(jì)時(shí)的按鈕效果

    Android實(shí)現(xiàn)倒計(jì)時(shí)的按鈕效果

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)倒計(jì)時(shí)的按鈕效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-12-12
  • Flutter 開發(fā)一個登錄頁面

    Flutter 開發(fā)一個登錄頁面

    登錄頁面在 App 開發(fā)中非常常見,本篇借登錄頁面的開發(fā)介紹了文本框 TextField組件的使用,同時(shí)使用文本框的裝飾屬性實(shí)現(xiàn)了個性化文本框設(shè)置。
    2021-06-06
  • Android獲取其他應(yīng)用中的assets資源

    Android獲取其他應(yīng)用中的assets資源

    今天小編就為大家分享一篇關(guān)于Android獲取其他應(yīng)用中的assets資源,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2019-01-01

最新評論

淮南市| 锡林浩特市| 宁蒗| 荃湾区| 合山市| 文成县| 竹北市| 龙山县| 榆社县| 博白县| 连云港市| 包头市| 松阳县| 资阳市| 台南县| 法库县| 武平县| 龙泉市| 开化县| 六安市| 阿拉善左旗| 宁强县| 公主岭市| 五华县| 玉山县| 兴国县| 宁阳县| 资兴市| 德州市| 蚌埠市| 景宁| 榆树市| 筠连县| 尚义县| 新安县| 临城县| 芦山县| 呼和浩特市| 磐石市| 九江市| 漳浦县|