tjerkw / Android-SlideExpandableListView

A better ExpandableListView, with animated expandable views for each list item
Apache License 2.0
1.98k stars 741 forks source link

Still no sample to show how to handler item click listener #9

Closed maohieng closed 11 years ago

maohieng commented 11 years ago

I'm trying to find the solution here, but I still can't. Please provide the solution of how to handler item click listener.

tjerkw commented 11 years ago

What do you mean with "handler item click listener". What event do you want to listen for?

maohieng commented 11 years ago

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.

tjerkw commented 11 years ago

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.

girishnair1234567 commented 11 years ago

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 ??

maohieng commented 11 years ago

For this condition, you need to modify the library ^^.

  1. Class AbstractSlideExpandableListAdapter :
    • public abstract View getExpandToggleButton(View parent);
    • public void enableFor(View parent, int position) { View more = getExpandToggleButton(parent); View itemToolbar = getExpandableView(parent); enableFor(more, itemToolbar, position); }
  2. Class SlideExpandableListAdapter :
    • @Override public View getExpandToggleButton(View parent) { View view = parent.findViewById(toggle_button_id); return view; }

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.

girishnair1234567 commented 11 years ago

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

tjerkw commented 11 years ago

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
));
girishnair1234567 commented 11 years ago

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

vuhung3990 commented 10 years ago
    @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