I'm currently building an android app, with expandable list view. I'm using the library from https://github.com/chrisbanes/Android-PullToRefresh
The problem is there's no method for child click listener on PullToRefreshExpandableListView class. The class also can not set adapter extended from BaseExpandableListAdapter class
Can anyone help? or is there any library which support pull-up-down Expandable Listview beside this library? Thank you
use below code this will give you child click of PullToRefreshExpandableListView.
PullToRefreshExpandableListView PULL_EXLIST_VIEW;
PULL_EXLIST_VIEW = (PullToRefreshExpandableListView) findViewById(R.id.listView1);
ExpandableListView EXLIST_VIEW = PULL_EXLIST_VIEW.getRefreshableView();
EXLIST_VIEW.setOnChildClickListener(new OnChildClickListener() {
#Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
System.out.println("Child clicked");
return false;
}
});
Related
How to keep a child selection after collapse the expandable list view. When the user selects one child in expandable list view after it collapse it will not shown ..
Implement onChild click listenr in your fragment/Activity
set the listener like below
expandableListView.setOnChildClickListener(this);
Code snippet:
#Override
public boolean onChildClick(ExpandableListView expandableListView, View view, int groupPosition, int childPosition, long id) {
YourView yourView = (YourView) view.findViewById(R.id.view_id);
YourDataItem item = (YourDataItem) yourView.getTag();
item.isSelected = !yourView.isChecked();
yourView.setChecked(item.isSelected);
}
Don't forget to setTag() in your adapter
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.
}
});
Hi guys I am trying to change the value of the parent by clicking a child in a expandable list. I have looked for a solution but cant find anything.
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id){
ExpandableListAdapter itemAdapter = parent.getExpandableListAdapter();
String selectedItem = (String)itemAdapter.getChild(groupPosition, childPosition);
groupHeader(selectedItem);
if(parent.isGroupExpanded(groupPosition)){
parent.collapseGroup(groupPosition);
}
return true;
}
});
An ExpandableListView depends on an adapter to obtain its values. Those values come from some sort of data structure, often an ArrayList or even a simple array. In your onChildClick(), pass a reference to the data structure used to build your ExpandableListAdapter and modify the data structure directly, followed by a call to notifyDataSetChanged().
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id)
{
ExpandableListAdapter itemAdapter = parent.getExpandableListAdapter();
String selectedItem = (String)itemAdapter.getChild(groupPosition, childPosition);
groupHeader(selectedItem);
if(parent.isGroupExpanded(groupPosition))
{
parent.collapseGroup(groupPosition);
}
// your logic here
// expandableListArrayList.add() or expandableListArrayList.remove()
// or whatever
itemAdapter.notifyDataSetChanged();
return true;
}
});
You probably have to extend the adapter to create the functionality you need. Your question is a bit nebulous because I can't see the overall structure of your code, but this should give you a running start.
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 have an ExpandableListView view and I've implemented OnChildClickListener, but I need to get the group of that child, more specifically - the text staying as a label of that group.
How can I do that?
Should I implement OnGroupClickListener?
Can somebody show me how to use getPackedPositionGroup() or any of the getPacked<somethingf>() methods to get to the text on the group element of expandable list view?
[Edit - addition]
the called is in Map class, which is something like this:
public class MapCommand extends Activity implements OnChildClickListener {
.....
#Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
firstStepSwitcher(v, childPosition);
///HERE IS WHERE I WANT TO FIND THE GROUP!!!
return true;
}
}
The view itself is in the layout XML. I do not manage its display manually.
And it has separate class for adapter.
What I did wrong was that I used to take the adapter for that ExpandableListView like this:
in (public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id))
parent.getAdapter();
But after looking into detail in the specification I found that I should take it like this:
ExpandableListAdapter mAdapter = parent.getExandableListAdapter();
from there on I do not have problem to get my group by calling:
String groupName = (String) mAdapter.getGroup(groupPosition);