ExpandableListView with seekbar doesn't expand - android

I've made a custom BaseExpandableListAdapter. I'm trying to display a seekbar on some (not all) group views. To do this, I'm inflating a custom layout with a seekbar in it wich I hide/unhide depending on the group.
The problem is that these group views WITH VISIBLE seekbar doesn't expand. The ones with HIDDEN seekbar do expand. All group views have children.
This is my getGroupView
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
if(convertView == null) {
convertView = inflater.inflate(com.voy.sima.R.layout.itemcomplejo, parent, false);
}
Complejo entry = (Complejo)getGroup(groupPosition);
SeekBar sbDesarrollo = (SeekBar) convertView.findViewById(R.id.sbDesarrollo);
sbDesarrollo.setVisibility(View.INVISIBLE);
if(entry.getId() == 2) {
sbDesarrollo.setVisibility(View.VISIBLE);
}
}
What am I missing? I'm sure it's something silly but it's driving me crazy.

There is open source project from Google android developer for expanding Listview with animation.
Here is the link: http://developer.android.com/shareables/devbytes/ListViewExpandingCells.zip
And this is an explanation on YouTube of this project.
I hope this could help you ..

I've figured it out. Adding sbDesarrollo.setFocusable(false); did the trick.
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
if(convertView == null) {
convertView = inflater.inflate(com.voy.sima.R.layout.itemcomplejo, parent, false);
}
Complejo entry = (Complejo)getGroup(groupPosition);
SeekBar sbDesarrollo = (SeekBar) convertView.findViewById(R.id.sbDesarrollo);
sbDesarrollo.setVisibility(View.INVISIBLE);
if(entry.getId() == 2) {
sbDesarrollo.setVisibility(View.VISIBLE);
sbDesarrollo.setFocusable(false);
}
}

Related

Group Indicator is not coming in the right side of Expandable List view

Group Indicator is not coming in the right side of Expandable List view in android Even if I have applied all the given solution for it but its not working
In the xml file
ExpandableListView
android:groupIndicator="#null"
In adapter
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
if (isExpanded) {
groupHolder.img.setImageResource(R.drawable.group_down);
} else {
groupHolder.img.setImageResource(R.drawable.group_up);
}
}
You have to use custom image to achieve this.

how to get view of group in expandablelistview in android?

im blazilian so, my english is not good.
So.. i need get view of group in expandablelistview for get your object tag throught view.getTag() method.
follow me in this example:
ExpandableListView
--> group (i need this view)
----> child
----> child
----> child
--> group (i need this view)
----> child
----> child
My code:
#Override
public boolean onChildClick(final ExpandableListView parent, final View v,
final int groupPosition, final int childPosition, final long id) {
/* I NEED GET VIEW OF GROUP FOR GET YOUR TAG*/
View vParent = parent.getChildAt(groupPosition); // dont work after first group
Programa v2 = (Programa) parent.getTag(); // return null
// v parameter is a child of group
return true;
}
in my adapter:
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
TwoLineListItem view = (TwoLineListItem) LayoutInflater.from(contexto)
.inflate(android.R.layout.simple_expandable_list_item_2,
parent, false);
String programa = map.keySet().toArray(new String[map.keySet().size()])[groupPosition];
view.getText1().setText(programa);
view.getText2().setText("PROGRAMA LOCAL");
view.setTag(programas.get(groupPosition)); // i need get this in child click listener
return convertView = view;
}
any idea? thanks
To get the group view from an ExpandableListView, you do something as follows:
public View getGroupView(ExpandableListView listView, int groupPosition) {
long packedPosition = ExpandableListView.getPackedPositionForGroup(groupPosition);
int flatPosition = listView.getFlatListPosition(packedPosition);
int first = listView.getFirstVisiblePosition();
return listView.getChildAt(flatPosition - first);
}
If your code is correct, you want to get the group view for the child so that you can call getTag() on it, correct?
If so, why not just skip that step and access the value of the tag, set by programas.get(groupPosition) manually?
You can do this by calling:
programas.get(groupPosition) right on the top of your onChildClick method since you get the group position value there too.
Edit in response to your comment:
The issue here is that you're not going to be able to get the view of the group through the adapter since it might involve recreating the view due to recycling of views in lists. If this method doesn't work, I strongly suggest modifying your code to make it work.
If programas is one of the inputs to your adapter, then call getGroup(groupPosition) on your adapter to access it. Else, make a public method in your adapter class to allow retrieval of that value.
I tried AedonEtLIRA answer but it only obtained the first item in the list.
My solution was to set a tag in my adapter's getGroupView method.
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.listitem_group, null);
}
//This is your data object that you might be using for storage that can be returned by your getGroup(groupPosition) function
GroupDataDto groupDataDto = (GroupDataDto) getGroup(groupPosition);
String name = groupDataDto.getName();
convertView.setTag(name);
...
Now in your Fragment / Activity, in your onGroupExpand and onGroupCollapse:
GroupDataDto groupDataDto = (GroupDataDto) listAdapter.getGroup(groupPosition);
ImageView arrow = (ImageView) getView().findViewWithTag(groupDataDto.getName()).findViewById(R.id.expandable_arrow_down);
Then I can do my animation on the arrow, which is why I wanted to get that group view.
Well I used the following code to access a TextView in a group:
#Override
public boolean onChildClick(final ExpandableListView parent, final View v,
final int groupPosition, final int childPosition, final long id) {
View vParent = mAdapter.getGroupView(groupPosition, true, null, null);
Programa v2 = (Programa) vParent.getTag();
return true;
}
I hope it helps

How to hide group in ExpandableListView in android

In ExpandableListView if I only have one group. I want to hide that group, only the group's data show that. Please help me
1) Hide the Group indicator with:
android:groupIndicator="#android:color/transparent"
2) return an empty FrameLayout for the groups you want to be empty like this:
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
//By default the group is hidden
View view = new FrameLayout(context);
String groupTitle = getGroup(groupPosition).toString();
//in case there's more than one group and the group title is not empty then show a TextView within the group bar
if(getGroupCount() > 1 && !groupTitle.isEmpty()) {
view = getGenericView();
((TextView)view).setText(groupTitle);
}
return view;
}
3) Call expandGroup for the groups you are not showing the group bar:
expandableListView.expandGroup(GROUP_ID);
4) If you want to show a group indicator you have to add an ImageView programmatically from the getGroupView method. Check this blog post for more info on hiding/showing group indicator: Hiding group indicator for empty groups
I had the same problem and this solveed my issue.
In your Listview's adapter add the following to the getGroupView.
if (groupPosition == 0) {
convertView = layoutInflater.inflate(R.layout.blank_layout, null);
} else {
convertView = layoutInflater.inflate(R.layout.group_indicator_cell,null);
}
This will blank the 0th groupof the list.
Where blank layout is a layout with some view inside having layout_height=0dp.
It works!
Instead of returning a empty layout, I travel through all children in the layout and call view.setVisibility(View.Gone) when there is no data.
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
LinearLayout lo;
if (convertView != null) {
lo = (LinearLayout) convertView;
} else {
lo = (LinearLayout) mLayoutInflater.inflate(R.layout.list_item_group_header, parent, false);
}
int visibility = mData.size() == 0 ? View.GONE : View.VISIBLE;
for (int i = 0; i < lo.getChildCount(); i++) {
lo.getChildAt(i).setVisibility(visibility);
}
return lo;
}
Set the parent iew vlayout params hieght to zero in your BaseExpandableListAdapter so that you can hide you parent

Android: First element list view acting weird

In my Android application I have a ListView with 5 elements. I created a custom adapter, in order to change the background of some elements of the listView. For example, the second item of the list view is not ready yet, so I want to setBackground(Color.Gray), so he can look like it's not done it. In order to do that, I Overrided the getView() method from ArrayAdapter in my custom adapter how it follows:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
if(!itensAvailable[position]) v.setBackgroundColor(Color.Gray);
return v;
}
The weird thing is, no matter if I use the boolean itensAvailable[position] or !itensAvailable[position] the first element of the list always has it's background changed! All the others elements of the list are behaving like expected, except the first one. More weird than that, if I do
if(position == 2) v.setBackgroundColor(Color.Gray);
it changes the background from the item in the position 2, and the first item as well! If I do
if(position == 2) {
v.setBackgroundColor(Color.Gray);
System.out.println(v.getText());
}
Even more weird! Only the text from the position 2 gets printed, not the text from the first item.
What is going on? Android bug? By the way, im testing it on a XOOM 3.2 Honeycomb device.
And obviously, if I comment this if code, the first item doens't has it's background changed.
It is very strange !
What happens if you write :
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
if(!itensAvailable[position]) v.setBackgroundColor(Color.Gray);
else v.setBackgroundColor(Color.Transparent);
return v;
}
I cannot explain the weird behaviour. Can you try the following code and see if it solves your problem -
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = to the view to be displayed;
}
if(!itensAvailable[position]) convertView.setBackgroundColor(Color.Gray);
return convertView;
}
I Have the exact same issue. Strange indeed!
What worked for me is to remove the line
View v = super.getView(position, convertView, parent);
and use instead -
LayoutInflater inflater = LayoutInflater.from(getContext());
View v = inflater.inflate(R.layout.__my__layout__, parent, false);
.... more view manipulations ....
hope it helps!

custom views not updating with OnGroupClickListener on ExpandableListView

I have custom groupViews that need to change state when they are expanded and collapsed.
If the same group view is expanded it toggles between two states.
The problem i'm having is that the expand method seems to be pulling up some cached version of the views because my updates aren't visible after calling expandGroup.
If my listener returns true (handles the whole event itself) without calling expandGroup the update does happen. So something is happening with expandGroup that only allows cached view to be drawn.
I have tried invalidating() just about everything. I've tried firing off data update events on the List View. i've tried all this other stuff as well:
expandableList.setGroupIndicator(null);
expandableList.setAlwaysDrawnWithCacheEnabled(false);
expandableList.setWillNotCacheDrawing(true);
expandableList.setItemsCanFocus(false);
no luck on any of those :(
Here's my onClick code:
expandableList.setOnGroupClickListener(new OnGroupClickListener() {
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
MusicTrackRow mt = (MusicTrackRow) v;
if (mt.isPlaying == true) {
mt.setPaused();
} else {
mt.setPlaying();
}
mt.invalidate();
parent.invalidate();
trackAdapter.notifyDataSetInvalidated();
//need to call expandGroup if the listener returns true.. if returning false expandGroup is //returned automatically
expandableList.expandGroup(groupPosition); //no view refresh
return true;
Found a solution finally!
When the expandable list is expanded a call to getGroupview in the adapter is made for every group on the list.
That is the place where you want to effect changes.
the isExpanded argument lets you determine which group view is expanded.
Then you can do stuff that looks like this:
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
View v;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.expandablelistitem, null);
} else {
v = convertView;
}
int id = (!isExpanded) ? R.drawable.list_plus_selector
: R.drawable.list_minus_selector;
TextView textView = (TextView) v.findViewById(R.id.list_item_text);
textView.setText(getGroup(groupPosition).toString());
ImageView icon = (ImageView) v.findViewById(R.id.list_item_icon);
icon.setImageResource(id);
return v;
}

Categories

Resources