Closed maohieng closed 11 years ago
What do you mean with "handler item click listener". What event do you want to listen for?
Here is what I do :
ActionSlideExpandableListView list;
ListFavoriteAdapter adapter = new ListFavoriteAdapter(getActivity(), data); list.setAdapter(adapter); list.setItemActionListener(new ActionSlideExpandableListView.OnActionClickListener() { ... //here I can handle quick action button click });
list.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int index, long id) { // Here is what I can not get it Toast.makeText(getActivity(), "Item " + index, Toast.LENGTH_SHORT).show(); } });
Is there something wrong with my code? I don't understand why I cannot get the result from the whole item of list clicked.
Please help.
An answer to your question can be found here: http://stackoverflow.com/questions/1518338/setonitemclicklistener-not-working-on-custom-listview-android
However i think the expand button will not work anymore, since you made the whole list item clickable.
You could also add an extra event listener on the expandablebutton in the ListAdapter.getView method.
Since this is not an issue with the library i;m closing this one. Feel free to open it again if you think it is a library problem.
I tried to access the expandable button using this I have used a TextView instead of button txt = (TextView) v.findViewById(R.id.expandable_toggle_button); I cant get the onclick event for it ??
For this condition, you need to modify the library ^^.
That's it. You can use with whatever view you want (but don't forget to set clickable=true for your view :) ).
This is a very good and useful library. Thank you, tjerkw.
I tried placing logs into those place and it seem to do no difference Those logs are fired only once the list in collapsed and not when the Button is clicked What i am saying is the BUTTON that you used is not sending me the onclick for it
The textview that i mention is the same Button except i have chaged it from Button to TextView
I still don't fully understand you completely. What you can do is the following:
Use a normal ListView Create your own ListAdapter. In your own ListAdapter in the getView method set an onclick listener on the view you want. Wrap your adapter in an SlideExpandableListAdapter.
Like this:
ListAdapter adapter = new ListAdapter() {
public View getView(final int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
v.findViewById(R.id.your_view_id).setOnClickListener(yourListener);
return v;
}
}
list.setAdapter(new SlideExpandableListAdapter(
adapter, R.id.more_button, R.id.expandable_view
));
Ya I tried but the onclick doesnt work for id="expandable_toggle_button", Anywa i found the solution i had to modfiy the AbstractSlideExpandableListAdapter class Thanks
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if(convertView == null){
convertView = inflater.inflate(R.layout.expandable_list_item, null);
}
TextView textView = (TextView)convertView.findViewById(R.id.text);
textView.setText((String)getItem(position));
RelativeLayout layout = (RelativeLayout)convertView.findViewById(R.id.item);
layout.setClickable(true);
layout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.e("sdsasa", "clicked "+position);
}
});
return convertView;
}
you can custom adapter, here is sample to handle onItemclick event, this work but maybe bad idea sorry
I'm trying to find the solution here, but I still can't. Please provide the solution of how to handler item click listener.