How Can I Disable Expandable Listview Icon From It's Header In Android?
I created an ExpandableListView in android. I have some categories which have some more sub-categories. While other do not have sub-categories. How can I remove the icon if it does
Solution 1:
First of all , remove the default icon of expandable listview
<ExpandableListView [...]
android:groupIndicator="@null" />
And than in your adapter of Expandable listview in getGroupView
method use following code for it
@Overridepublic View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
StringheaderTitle= (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflaterinfalInflater= (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.YOUR_LIST_GROUP_XML, null);
}
TextViewheader_tv= (TextView) convertView.findViewById(R.id.list_header_tv);
ImageViewarrow_iv=(ImageView) convertView.findViewById(R.id.arrow_iv);
header_tv.setText(headerTitle);
Booleancheck=false;
try {
YOUR_HAS_MAP_LIST.get(this._listDataHeader.get(groupPosition))
.get(0);
}
catch (Exception ex)
{
check = true;
ex.printStackTrace();
}
if(check)
{
arrow_iv.setVisibility(View.INVISIBLE);
}
if(isExpanded)
{
arrow_iv.setImageResource(R.drawable.UP_ARROW);
}
else
{
arrow_iv.setImageResource(R.drawable.DOWN_ARROW);
}
return convertView;
}
Solution 2:
There is single problem in above answer. While you expand the category other category's icon was also disable. Because, at the first time code goes to try and it's not goes outside of try until your listdatachild.get(listdataheader.get(i)).get(0) found. so, it not going to in if(check) everytime. Therefor, icon were remaing hidden.
Below is the perfect solution
@Overridepublic View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
StringheaderTitle= (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflaterinfalInflater= (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.YOUR_LIST_GROUP_XML, null);
}
TextViewheader_tv= (TextView) convertView.findViewById(R.id.list_header_tv);
ImageViewarrow_iv=(ImageView) convertView.findViewById(R.id.arrow_iv);
header_tv.setText(headerTitle);
Booleancheck=false;
try {
if(YOUR_HAS_MAP_LIST.get(this._listDataHeader.get(groupPosition))
.get(0)==null){}
else{
if (isExpanded) {
arrow_iv.setImageResource(R.drawable.arrow_up);
} else {
arrow_iv.setImageResource(R.drawable.arrow_down);
}
}
}
catch (Exception ex)
{
check = true;
ex.printStackTrace();
}
if(check)
{
arrow_iv.setVisibility(View.INVISIBLE);
}
else{
arrow_iv.setVisibility(View.VISIBLE);
}
return convertView;
}
Post a Comment for "How Can I Disable Expandable Listview Icon From It's Header In Android?"