I am working on the ExpandableListView I have completed the work, now only one thing that I want to do is I don't want the ListView to be DropDown on click of the Expandable List View rather I want to show it opened with all the Items displayed inside without performing any click on them.
Can anyone tell me how can i do that particularly.
Do this for every one of the groups to expand them:
listView1.expandGroup(int groupPosition);
If you want to prevent group collapse, then do this:
listView1.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener()
{
public boolean onGroupClick(ExpandableListView arg0, View itemView, int itemPosition, long itemId)
{
listView1.expandGroup(itemPosition);
return true;
}
});
Solution:- To Keep The Expandable list in Expanded mode all the times
It is actually very simple you dont need to do anything but just put this one line in your getGroupView of your adapter and your expandablelistview always be in opened/expanded state:--
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
View v = convertView;
your_expandableListview.expandGroup(groupPosition);
return v;
}
This works for sure... Enjoy..!
Open ExpandableListView Group:
listView.expandGroup(itemPosition);
Collapse ExpandableListView Group:
listView.collapseGroup(itemPosition);
Related
My problem is...
I use Expandable list view in my activity.
When the activity created it shows all the child group is collapsed.
I would like to expand all children while the expandable list view is populated.
like
for that, I used below code in getGroupView() method adapter class
ExpandableListView eLV = (ExpandableListView) parent
eLV.expandGroup(groupPosition,true);
now the groups are expanded but it can not allow me to collapse by clicking on the group header.
Simply add groupClickListener and return true for disabling collapse the child list. Add this code to your activity.
yourExpandableList.setOnGroupClickListener(new OnGroupClickListener() {
#Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
return true; // This way the expander cannot be collapsed
}
});
I create an Expandable ListView which contains 3 group and each group have several child.
In OnCreate i expand group one with exLv.expandGroup(0); then i want to click child of this group without user touch it (dynamically).
I tried exLv.setSelectedChild and it didn't work.
I just want to do this one time at the onCreate. How to do this?
In your activity class override the OnChildClickListener() method from list view.
expandbleList.setOnChildClickListener(new OnChildClickListener() {
#Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
//do something here.
}
});
I want to make an ExpandableListView which should always be showing its children elements
even after clicking the header, and it should not collapse. How could I implement this concept?
you can expand all groups one by one as below as mentioned in this post
ExpandableListView explst;
explst.expandGroup(0);
explst.expandGroup(1);
for disabling collapse you can define a OnGroupClickListener which returns true, like so: (as mentioned in this post)
explst.setOnGroupClickListener(new OnGroupClickListener() {
#Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
return true; // This way the expander cannot be collapsed
}
});
I am new to android and am trying to develop a new android app. But I am struggling to siolve one of the problems in my project.
I am using a listview extended from baseadapter and need to add a button in each row of thelistview. When I click on the button in any row of the listview, I want that it should be removed. However when I do so, some of the other buttons also get removed in the listview.
How can I solve this problem? Thank you..
You have an adapter, activity and some sort of data source
In your adapter you attach some data to buttons to be able to tell one from another:
public class ExpAdapter extends ListAdapter {
#Override
public View getView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
/* SOME CODE HERE*/
convertViewButton.setTag(buttonId);
return convertView;
}
/* SOME CODE HERE*/
}
in your activity you mark button id as the one to be hidden:
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
storageOfHiddenButtonsIds.add((Long)arg1.getTag());
}};
and then ListAdapter changes like this:
#Override
public View getView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
/* SOME CODE HERE*/
convertViewButton.setTag(buttonId);
if(storageOfHiddenButtonsIds.contains(buttonId))
{
convertViewButton.setVisiblity(View.GONE);
}
return convertView;
}
and when you want your adatper to change you, don't forget to call
this.expAdapterAllTaks.notifyDataSetChanged();
Sorry for any errors in my code, but i just wanted to give you an idea.
I faced same type of problem. ListView's setOnItemClickListener not works if you add item like a button on every listView item. Solution is use onClick in the list Item layout(which you use in custom adapter file) as
<ImageButton
android:id="#+id/my_delete"
android:onClick="onDeleteButtonClickListener"
... and so on />
where onDeleteButtonClickListener is a method in the activity where you set the adapter in listview.
public void onDeleteButtonClickListener(View v) {
// your code
}
here listItem means the individual row item of a ListView
Helpful Link: Button in ListView item
I want to customize expandable list view such a way that when user clicks on any group view of that expandable list view then a dialog will be shown but list view will not expand.After selecting some thing from the dialog when user click on ok of the dialog the list view will expand and will show data on the base on what selected from dialog.
Can anybody give me any idea how can I implement it?
Try the following, it should do the trick:
mListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
#Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
boolean shouldIExpandGroups = doSomething();
if (shouldIExpandGroups)
return false; // This will cause ListView to expand
else
return true; // This will cause ListView to ignore click
}
});