EN / USD
32
of 76
TEP , The Engineering Projects , Image

syedzainnasir

TEP , The Engineering Projects , Rating 7.5 7.5 / 10
TEP , The Engineering Projects , Icon Level: Moderator
TEP , The Engineering Projects , Icon Joined: 20 Mar 2022
TEP , The Engineering Projects , Icon Last Active: 2:21 PM
TEP , The Engineering Projects , Icon Location: TEP , The Engineering Projects , Flag
TEP , The ENgineering Projects , Icon TEP , The ENgineering Projects , Icon TEP , The ENgineering Projects , Icon TEP , The ENgineering Projects , Icon
Search filter Expandablelistview Header Items
TEP , The Engineering Projects , Calender Question: 09-Mar-2017
TEP , The Engineering Projects , Category In: Computer Software Projects
I'm about to create an expandableListview with implemented Searchview. My SearchView can filter child items and only the child items. I want to create a search filter that can also filter the header items in expandablelistview. how can I do that?

here's my code for the expandablelistview with search filter. here is my Adapter: [code]package com.teamamazing.search; import java.text.NumberFormat; import java.util.ArrayList; import java.util.Locale; import android.content.Context; import android.graphics.Typeface; import android.media.MediaPlayer; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseExpandableListAdapter; import android.widget.TextView; import android.view.View.OnClickListener; public class Accomodation_Adapter extends BaseExpandableListAdapter { private Context context; private ArrayList<AccomodationHeaderRow> headerRows; private ArrayList<AccomodationHeaderRow> originalList; public Accomodation_Adapter(Context context, ArrayList<AccomodationHeaderRow> headerRows) { this.context = context; this.headerRows = new ArrayList<AccomodationHeaderRow>(); this.headerRows.addAll(headerRows); this.originalList = new ArrayList<AccomodationHeaderRow>(); this.originalList.addAll(headerRows); } @Override public Object getChild(int groupPosition, int childPosition) { ArrayList<AccomodationChildRow> childRows = headerRows.get(groupPosition).getChildRow(); return childRows.get(childPosition); } @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; } @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view, ViewGroup parent) { AccomodationChildRow child = (AccomodationChildRow) getChild(groupPosition, childPosition); if (view == null) { LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = layoutInflater.inflate(R.layout.activity_accomodation_child_row, null); } TextView name = (TextView) view.findViewById(R.id.child_items);; name.setText(child.getName().trim()); return view; } @Override public int getChildrenCount(int groupPosition) { ArrayList<AccomodationChildRow> childRows = headerRows.get(groupPosition).getChildRow(); return childRows.size(); } @Override public Object getGroup(int groupPosition) { return headerRows.get(groupPosition); } @Override public int getGroupCount() { return headerRows.size(); } @Override public long getGroupId(int groupPosition) { return groupPosition; } @Override public View getGroupView(int groupPosition, boolean isExpanded, View view, ViewGroup parent) { AccomodationHeaderRow accomodationHeaderRow = (AccomodationHeaderRow) getGroup(groupPosition); if (view == null) { LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = layoutInflater.inflate(R.layout.activity_accomodation_header_row, null); } TextView heading = (TextView) view.findViewById(R.id.accomodation_headings); heading.setText(accomodationHeaderRow.getName().trim()); // If group is expanded then change the text into bold and change the // icon if (isExpanded) { heading.setTypeface(null, Typeface.BOLD); heading.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); } else { // If group is not expanded then change the text back into normal // and change the icon heading.setTypeface(null, Typeface.NORMAL); heading.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); } return view; } @Override public boolean hasStableIds() { return true; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return true; } public void filterData(String query){ query = query.toLowerCase(); Log.v("Accomodation_Adapter", String.valueOf(headerRows.size())); headerRows.clear(); if(query.isEmpty()){ headerRows.addAll(originalList); } else { for(AccomodationHeaderRow accomodationHeaderRow: originalList){ ArrayList<AccomodationChildRow> accomodationChildRows = accomodationHeaderRow.getChildRow(); ArrayList<AccomodationChildRow> newList = new ArrayList<AccomodationChildRow>(); for(AccomodationChildRow accomodationChildRow: accomodationChildRows){ if(accomodationChildRow.getName().toLowerCase().contains(query)){ newList.add(accomodationChildRow); } } if(newList.size() > 0){ AccomodationHeaderRow nAccomodationHeaderRows = new AccomodationHeaderRow(accomodationHeaderRow.getName(),newList); headerRows.add(nAccomodationHeaderRows); } } } Log.v("Accomodation_Adapter", String.valueOf(headerRows.size())); notifyDataSetChanged(); } }[/code]
TEP , The Engineering Projects , Icon Answer: 0 TEP , The Engineering Projects , Icon Views: 150 TEP , The Engineering Projects , Icon Followers: 85
Small Bio
TEP , The Engineering Projects , Tags
PLC
Robot
STM32
Arduino
AI
ESP32
Ladder Logic
PLC Projects
Programming
Communicates STM32
PLC Projects
Communicates PLC
Font Style
Alignment
Indenting and Lists
Insert Media
Insert Items

Want to leave an answer!

Word Count :0 Draft Saved at 12:42 am.