activity_main.xml
...................................................................................................................................................................
xml version="1.0"
encoding="utf-8"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.project.example.customexpendablelistviewdemo.MainActivity">
<ExpandableListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listViewforSeat">
</ExpandableListView>
</RelativeLayout>
...................................................................................................................................................................
List_summary_group.xml
...................................................................................................................................................................
xml version="1.0"
encoding="utf-8"
?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:padding="8dp"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="18dp"
android:id="@+id/textHeadertype" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/textheaderguest_Count"
android:layout_weight=".5"
android:paddingLeft="8dp"
/>
</LinearLayout>
</LinearLayout>
...................................................................................................................................................................
List_summary_child.xml
...................................................................................................................................................................
xml version="1.0"
encoding="utf-8"
?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#dddddd">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:padding="4dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/textchildtype" />
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/textchildguest_Count" />
<Button
android:layout_width="70dp"
android:layout_height="40dp"
android:id="@+id/chengeSeatBtn"/>
</LinearLayout>
</LinearLayout>
Summarychild.Java
...................................................................................................................................................................
public
class summarychild {
private String Count;
private String Ailrline;
private String GuestType;
public String getCount() {
return Count;
}
public void setCount(String count) {
Count = count;
}
public String getAilrline() {
return Ailrline;
}
public void setAilrline(String ailrline) {
Ailrline = ailrline;
}
public String getGuestType() {
return GuestType;
}
public void setGuestType(String guestType) {
GuestType = guestType;
}
private String Count;
private String Ailrline;
private String GuestType;
public String getCount() {
return Count;
}
public void setCount(String count) {
Count = count;
}
public String getAilrline() {
return Ailrline;
}
public void setAilrline(String ailrline) {
Ailrline = ailrline;
}
public String getGuestType() {
return GuestType;
}
public void setGuestType(String guestType) {
GuestType = guestType;
}
...................................................................................................................................................................
SummaryGroup.Java
...................................................................................................................................................................
public
class SummaryGroup {
private String Name;
private String count;
private ArrayList
Items;
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getCount() {
return count;
}
public void setCount(String count) {
this.count = count;
}
public ArrayList
getItems() {
return Items;
}
public void setItems(ArrayList items) {
Items = items;
}
}
private String Name;
private String count;
private ArrayList
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getCount() {
return count;
}
public void setCount(String count) {
this.count = count;
}
public ArrayList
return Items;
}
public void setItems(ArrayList
Items = items;
}
}
AdapterForSummarySeat.Java
public
class AdapterForSummarySeat
extends BaseExpandableListAdapter {
private Context context;
private ArrayList
groups;
private ArrayList
arraylist;
public static int count;
public static ArrayList AirlineName=new ArrayList<>();
public AdapterForSummarySeat(Context context, ArrayList groups) {
this.context = context;
this.groups = groups;
this.arraylist=new ArrayList();
this.arraylist.addAll(groups);
}
@Override
public int getGroupCount() {
return groups.size();
}
@Override
public int getChildrenCount(int groupPosition) {
ArrayList
summchList = groups.get(groupPosition).getItems();
return summchList.size();
}
@Override
public Object getGroup(int groupPosition) {
return groups.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
ArrayList
chList = groups.get(groupPosition).getItems();
return chList.get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
SummaryGroup group = (SummaryGroup) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater inf = (LayoutInflater) context
.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = inf.inflate(R.layout.list_summary_group, null);
}
TextView textHeadertype= (TextView) convertView.findViewById(R.id.textHeadertype);
TextView textheaderguest_Count= (TextView) convertView.findViewById(R.id.textheaderguest_Count);
textHeadertype.setText(group.getName());
textheaderguest_Count.setText(group.getCount());
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
final ViewHolder holder;
final int possition=childPosition;
final summarychild child = (summarychild) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_summary_child, null);
}
holder = new ViewHolder();
try {
holder.textchildtype = (TextView) convertView.findViewById(R.id.textchildtype);
holder.textchildguest_Count = (TextView) convertView.findViewById(R.id.textchildguest_Count);
holder.textchildtype.setText(child.getAilrline());
holder.textchildguest_Count.setText(child.getCount());
}catch (Exception e){
e.printStackTrace();
}
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public void filter(String charText) {
charText = charText.toLowerCase(Locale.getDefault());
groups.clear();
if (charText.length() == 0) {
groups.addAll(arraylist);
}
else
{
for (SummaryGroup sp : arraylist)
{
if (sp.getName().toLowerCase(Locale.getDefault()).contains(charText))
{
groups.add(sp);
}else if (sp.getCount().toLowerCase(Locale.getDefault()).contains(charText)){
groups.add(sp);
}
}
}
notifyDataSetChanged();
}
static class ViewHolder {
TextView textchildtype,textchildguest_Count;
}
}
private Context context;
private ArrayList
private ArrayList
public static int count;
public static ArrayList
public AdapterForSummarySeat(Context context, ArrayList
this.context = context;
this.groups = groups;
this.arraylist=new ArrayList
this.arraylist.addAll(groups);
}
@Override
public int getGroupCount() {
return groups.size();
}
@Override
public int getChildrenCount(int groupPosition) {
ArrayList
return summchList.size();
}
@Override
public Object getGroup(int groupPosition) {
return groups.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
ArrayList
return chList.get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
SummaryGroup group = (SummaryGroup) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater inf = (LayoutInflater) context
.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = inf.inflate(R.layout.list_summary_group, null);
}
TextView textHeadertype= (TextView) convertView.findViewById(R.id.textHeadertype);
TextView textheaderguest_Count= (TextView) convertView.findViewById(R.id.textheaderguest_Count);
textHeadertype.setText(group.getName());
textheaderguest_Count.setText(group.getCount());
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
final ViewHolder holder;
final int possition=childPosition;
final summarychild child = (summarychild) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_summary_child, null);
}
holder = new ViewHolder();
try {
holder.textchildtype = (TextView) convertView.findViewById(R.id.textchildtype);
holder.textchildguest_Count = (TextView) convertView.findViewById(R.id.textchildguest_Count);
holder.textchildtype.setText(child.getAilrline());
holder.textchildguest_Count.setText(child.getCount());
}catch (Exception e){
e.printStackTrace();
}
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public void filter(String charText) {
charText = charText.toLowerCase(Locale.getDefault());
groups.clear();
if (charText.length() == 0) {
groups.addAll(arraylist);
}
else
{
for (SummaryGroup sp : arraylist)
{
if (sp.getName().toLowerCase(Locale.getDefault()).contains(charText))
{
groups.add(sp);
}else if (sp.getCount().toLowerCase(Locale.getDefault()).contains(charText)){
groups.add(sp);
}
}
}
notifyDataSetChanged();
}
static class ViewHolder {
TextView textchildtype,textchildguest_Count;
}
}
MainActivity.Java
...................................................................................................................................................................
public
class MainActivity extends AppCompatActivity {
public static ArrayList SummaryGroupInfo;
public static ArrayList Group;
public static ArrayList SummarychildInfo;
public static ArrayList childInfo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SummaryGroupInfo = new ArrayList();
SummarychildInfo = new ArrayList();
Group = new ArrayList<>();
for (int i = 0; i < 3; i++) {
SummaryGroup SeatDeatils = new SummaryGroup();
SeatDeatils.setName("FlightNo " + i);
SeatDeatils.setCount("STD " + i);
SummaryGroupInfo.add(SeatDeatils);
}
for (int j = 0; j < 3; j++) {
summarychild child = new summarychild();
child.setAilrline("Airline " + j);
child.setCount("Count " + j);
child.setGuestType("GuestType " + j);
SummarychildInfo.add(child);
}
for (int g = 0; g < SummaryGroupInfo.size(); g++) {
SummaryGroup Info = new SummaryGroup();
SummaryGroup setinfo = SummaryGroupInfo.get(g);
Info.setName(setinfo.getName());
Info.setCount(setinfo.getCount());
childInfo = new ArrayList();
for (int c = 0; c < SummarychildInfo.size(); c++) {
summarychild childInfos = SummarychildInfo.get(c);
summarychild addchild = new summarychild();
addchild.setAilrline(childInfos.getAilrline());
addchild.setCount(childInfos.getCount());
childInfo.add(addchild);
}
Info.setItems(childInfo);
Group.add(Info);
}
final ExpandableListView list_alert = (ExpandableListView) findViewById(R.id.listViewforSeat);
final AdapterForSummarySeat adapter = new AdapterForSummarySeat(MainActivity.this, Group);
list_alert.setAdapter(adapter);
list_alert.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
int len = adapter.getGroupCount();
for (int i = 0; i < len; i++) {
if (i != groupPosition) {
list_alert.collapseGroup(i);
}
}
}
});
}
}
public static ArrayList
public static ArrayList
public static ArrayList
public static ArrayList
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SummaryGroupInfo = new ArrayList
SummarychildInfo = new ArrayList
Group = new ArrayList<>();
for (int i = 0; i < 3; i++) {
SummaryGroup SeatDeatils = new SummaryGroup();
SeatDeatils.setName("FlightNo " + i);
SeatDeatils.setCount("STD " + i);
SummaryGroupInfo.add(SeatDeatils);
}
for (int j = 0; j < 3; j++) {
summarychild child = new summarychild();
child.setAilrline("Airline " + j);
child.setCount("Count " + j);
child.setGuestType("GuestType " + j);
SummarychildInfo.add(child);
}
for (int g = 0; g < SummaryGroupInfo.size(); g++) {
SummaryGroup Info = new SummaryGroup();
SummaryGroup setinfo = SummaryGroupInfo.get(g);
Info.setName(setinfo.getName());
Info.setCount(setinfo.getCount());
childInfo = new ArrayList
for (int c = 0; c < SummarychildInfo.size(); c++) {
summarychild childInfos = SummarychildInfo.get(c);
summarychild addchild = new summarychild();
addchild.setAilrline(childInfos.getAilrline());
addchild.setCount(childInfos.getCount());
childInfo.add(addchild);
}
Info.setItems(childInfo);
Group.add(Info);
}
final ExpandableListView list_alert = (ExpandableListView) findViewById(R.id.listViewforSeat);
final AdapterForSummarySeat adapter = new AdapterForSummarySeat(MainActivity.this, Group);
list_alert.setAdapter(adapter);
list_alert.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
int len = adapter.getGroupCount();
for (int i = 0; i < len; i++) {
if (i != groupPosition) {
list_alert.collapseGroup(i);
}
}
}
});
}
}
0 comments