布局文件:
/SIM_Card_Demo/res/layout/inbox.xml
<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:background=“@drawable/bg”
android:orientation=“vertical” >
<RelativeLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:background=“@drawable/banner_bg” >
<ImageButton
android:id=“@+id/imgBtn_Sort”
android:layout_width=“@dimen/banner_btn_width”
android:layout_height=“wrap_content”
android:background=“@drawable/banner_btn_bg_selector”
android:src=“@drawable/sort” />
<ImageView
android:id=“@+id/img_DividerSort”
android:layout_width=“wrap_content”
android:layout_height=“42dp”
android:layout_toRightOf=“@+id/imgBtn_Sort”
android:src=“@drawable/banner_divider” />
<ImageView
android:id=“@+id/img_DividerSearch”
android:layout_width=“wrap_content”
android:layout_height=“42dp”
android:layout_toLeftOf=“@+id/imgBtn_Search”
android:src=“@drawable/banner_divider” />
<LinearLayout
android:id=“@+id/linear_Title”
android:layout_width=“wrap_content”
android:layout_height=“42dp”
android:layout_centerHorizontal=“true”
android:gravity=“center_vertical” >
<TextView
android:id=“@+id/text_Title”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“@string/inbox”
android:textColor=“@color/white”
android:textSize=“22sp”
android:textStyle=“bold” />
<TextView
android:id=“@+id/text_MailCount”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“(0/0)”
android:textColor=“@color/white”
android:textSize=“14sp”
android:textStyle=“bold” />
<RelativeLayout
android:layout_width=“40dp”
android:layout_height=“42dp”
android:layout_alignParentRight=“true”
android:layout_marginRight=“54dp” >
<ImageView
android:id=“@+id/img_Synchronizing”
android:layout_width=“18dp”
android:layout_height=“18dp”
android:layout_centerInParent=“true”
android:contentDescription=“@string/empty”
android:scaleType=“fitXY”
android:src=“@drawable/synchronizing” />
<ImageButton
android:id=“@+id/imgBtn_Search”
android:layout_width=“@dimen/banner_btn_width”
android:layout_height=“wrap_content”
android:layout_alignParentRight=“true”
android:background=“@drawable/banner_btn_bg_selector”
android:contentDescription=“@string/search”
android:src=“@drawable/search” />
<RelativeLayout
android:layout_width=“match_parent”
android:layout_height=“match_parent” >
<ExpandableListView
android:id=“@+id/list_Inbox”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:cacheColorHint=“@color/transparent”
android:childDivider=“@color/transparent”
android:divider=“@drawable/list_divider”
android:fastScrollEnabled=“true”
android:groupIndicator=“@color/transparent”
android:listSelector=“@color/transparent”
android:scrollbars=“none” />
组列表项
/SIM_Card_Demo/res/layout/group_item.xml
<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:background=“@drawable/bg”
android:orientation=“vertical” >
<RelativeLayout
android:layout_width="
match_parent"
android:layout_height=“wrap_content”
android:background=“@drawable/banner_bg” >
<ImageButton
android:id=“@+id/imgBtn_Sort”
android:layout_width=“@dimen/banner_btn_width”
android:layout_height=“wrap_content”
android:background=“@drawable/banner_btn_bg_selector”
android:src=“@drawable/sort” />
<ImageView
android:id=“@+id/img_DividerSort”
android:layout_width=“wrap_content”
android:layout_height=“42dp”
android:layout_toRightOf=“@+id/imgBtn_Sort”
android:src=“@drawable/banner_divider” />
<ImageView
android:id=“@+id/img_DividerSearch”
android:layout_width=“wrap_content”
android:layout_height=“42dp”
android:layout_toLeftOf=“@+id/imgBtn_Search”
android:src=“@drawable/banner_divider” />
<LinearLayout
android:id=“@+id/linear_Title”
android:layout_width=“wrap_content”
android:layout_height=“42dp”
android:layout_centerHorizontal=“true”
android:gravity=“center_vertical” >
<TextView
android:id=“@+id/text_Title”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“@string/inbox”
android:textColor=“@color/white”
android:textSize=“22sp”
android:textStyle=“bold” />
<TextView
android:id=“@+id/text_MailCount”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“(0/0)”
android:textColor=“@color/white”
android:textSize=“14sp”
android:textStyle=“bold” />
<RelativeLayout
android:layout_width=“40dp”
android:layout_height=“42dp”
android:layout_alignParentRight=“true”
android:layout_marginRight=“54dp” >
<ImageView
android:id=“@+id/img_Synchronizing”
android:layout_width=“18dp”
android:layout_height=“18dp”
android:layout_centerInParent=“true”
android:contentDescription=“@string/empty”
android:scaleType=“fitXY”
android:src=“@drawable/synchronizing” />
<ImageButton
android:id=“@+id/imgBtn_Search”
android:layout_width=“@dimen/banner_btn_width”
android:layout_height=“wrap_content”
android:layout_alignParentRight=“true”
android:background=“@drawable/banner_btn_bg_selector”
android:contentDescription=“@string/search”
android:src=“@drawable/search” />
<RelativeLayout
android:layout_width=“match_parent”
android:layout_height=“match_parent” >
<ExpandableListView
android:id=“@+id/list_Inbox”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:cacheColorHint=“@color/transparent”
android:childDivider=“@color/transparent”
android:divider=“@drawable/list_divider”
android:fastScrollEnabled=“true”
android:groupIndicator=“@color/transparent”
android:listSelector=“@color/transparent”
android:scrollbars=“none” />
子列表项
/SIM_Card_Demo/res/layout/child_item.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:orientation=“vertical”
android:background=“@drawable/item_bg”
<TextView
android:id=“@+id/textView1”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:textColor=“#ffff0000”
android:text=“SIM卡状态:” />
<TextView
android:id=“@+id/tv_sim_status”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:textColor=“#ff00ff00”
android:text=“@string/app_name” />
自定义适配器(重要)
/SIM_Card_Demo/src/com/wwj/sim/demo/InboxListAdapter.java
package com.wwj.sim.demo;
import java.util.List;
import java.util.Map;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
/**
-
自定义下列列表适配器
-
@author wwj
-
注:要继承BaseExpandableListAdpater
*/
public class InboxListAdapter extends BaseExpandableListAdapter {
private Inbox inbox;
private ExpandableListView list_Inbox;
private List<Map<String, Object>> groupList;
private List<Map<String, String>> childList;
private LayoutInflater inflater;
/**
-
构造函数
-
@param inbox
-
Activity对象引用
-
@param list_Inbox
-
下拉列表对象引用
-
@param data
-
数据
*/
public InboxListAdapter(Inbox inbox, ExpandableListView list_Inbox,
List<Map<String, Object>> groupList,
List<Map<String, String>> childList) {
super();
this.inbox = inbox;
this.list_Inbox = list_Inbox;
this.groupList = groupList;
this.childList = childList;
inflater = LayoutInflater.from(inbox);
}
/**
-
@author wwj
*/
private class GroupViewHolder {
ImageButton imgBtn_Photo;
TextView tv_name;
TextView tv_number;
TextView tv_details;
ImageView img_status;
public GroupViewHolder(View convertView) {
imgBtn_Photo = (ImageButton) convertView
.findViewById(R.id.imgBtn_Photo);
img_status = (ImageView) convertView.findViewById(R.id.img_Status);
tv_details = (TextView) convertView.findViewById(R.id.text_Details);
tv_name = (TextView) convertView.findViewById(R.id.text_Name);
tv_number = (TextView) convertView.findViewById(R.id.text_Number);
// 这个是防止图片聚焦,造成列表不能点击
imgBtn_Photo.setFocusable(false);
}
}
private class ChildViewHolder {
TextView tv_sim_status;
public ChildViewHolder(View converView) {
tv_sim_status = (TextView) converView
.findViewById(R.id.tv_sim_status);
}
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View converView, ViewGroup parent) {
final ChildViewHolder childViewHolder;
if (converView == null) {
converView = inflater.inflate(R.layout.child_item, null);
childViewHolder = new ChildViewHolder(converView);
converView.setTag(childViewHolder);
} else {
childViewHolder = (ChildViewHolder) converView.getTag();
}
childViewHolder.tv_sim_status.setText(childList.get(childPosition)
.get(“tv_sim_status”));
return converView;
}
@Override
public int getChildrenCount(int groupPosition) {
return childList.size();
}
@Override
public Object getGroup(int groupPosition) {
return groupList.get(groupPosition);
}
@Override
public int getGroupCount() {
return groupList.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
final GroupViewHolder groupViewHolder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.group_item, null);
groupViewHolder = new GroupViewHolder(convertView);
convertView.setTag(groupViewHolder);
} else {
groupViewHolder = (GroupViewHolder) convertView.getTag();
}
groupViewHolder.img_status.setImageResource(R.drawable.mail_status_new);
groupViewHolder.tv_name.setText(groupList.get(groupPosition)
.get(“username”).toString());
groupViewHolder.tv_number.setText(groupList.get(groupPosition)
.get(“number”).toString());
groupViewHolder.tv_details.setText(groupList.get(groupPosition)
.get(“detail”).toString());
groupViewHolder.imgBtn_Photo
.setImageResource(R.drawable.contact_photo_default);
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int arg0, int arg1) {
return false;
}
}
/SIM_Card_Demo/src/com/wwj/sim/demo/Inbox.java
package com.wwj.sim.demo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.widget.ExpandableListView;
public class Inbox extends Activity {
public ExpandableListView list_Inbox; //下拉List控件
public InboxListAdapter adapter;
private TelephonyManager telephonyManager; //用来获取电话的一些信息
List<Map<String, Object>> groupList;
List<Map<String, String>> childList;
String sim_status;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.inbox);
sim_status = readSIMCard();
getData();
//找到这个控件
list_Inbox = (ExpandableListView) findViewById(R.id.list_Inbox);
list_Inbox.setAdapter(new InboxListAdapter(Inbox.this, list_Inbox, groupList, childList));
list_Inbox.setOnGroupExpandListener(new OneListItemExpandListener(list_Inbox));
}
void getData() {
groupList = new ArrayList<Map<String,Object>>();
Map<String, Object> groupMap = new HashMap<String, Object>();
最后
小编这些年深知大多数初中级Android工程师,想要提升自己,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此我收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人
都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
资料⬅专栏获取
ildList;
String sim_status;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.inbox);
sim_status = readSIMCard();
getData();
//找到这个控件
list_Inbox = (ExpandableListView) findViewById(R.id.list_Inbox);
list_Inbox.setAdapter(new InboxListAdapter(Inbox.this, list_Inbox, groupList, childList));
list_Inbox.setOnGroupExpandListener(new OneListItemExpandListener(list_Inbox));
}
void getData() {
groupList = new ArrayList<Map<String,Object>>();
Map<String, Object> groupMap = new HashMap<String, Object>();
最后
小编这些年深知大多数初中级Android工程师,想要提升自己,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此我收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
[外链图片转存中…(img-Go2zcc3s-1719020991130)]
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人
都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
资料⬅专栏获取