2

I'm developing an Android app and I'm having trouble with expandableList. I found a sample code on the web and I tried to adapt it to my case. I tried to compare my code to the code I found on the web and they looks like very similar, but my code didn't work. When I try to run the app the phone load correctly the view with the expandable list, it shows the group list but when I tap on the row that I want to expand it doesn't shows anything. My code is the follow:

package it.bitmama.interactv2.adapter;

import it.bitmama.interactv2.R;

import java.util.Calendar;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ExpandableListAdapter extends BaseExpandableListAdapter {
    private Activity context;
    private List<String> episodes;
    private Map<String, List<String>> episodeData;  

    public ExpandableListAdapter(Activity context, List<String> episodes, Map<String, List<String>>episodeData) {
        this.context = context;
        this.episodes = episodes;
        this.episodeData = episodeData;
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return episodeData.get(episodes.get(groupPosition)).get(childPosition);
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public View getChildView(final int groupPosition, final int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {
        final String episode = (String) getChild(groupPosition, childPosition);
        LayoutInflater inflater = context.getLayoutInflater();

        if (convertView == null) {
            convertView = inflater.inflate(R.layout.child_item, null);
        }

        Log.d("das", "" + episode);

        TextView item = (TextView) convertView.findViewById(R.id.episodeTime);

        ImageView add = (ImageView) convertView.findViewById(R.id.addCalendar);
        add.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Log.d("EVENTI", "Aggiungere al calendario");

                Calendar cal = Calendar.getInstance();
                Intent intent = new Intent(Intent.ACTION_EDIT);
                intent.setType("vnd.android.cursor.item/event");
                intent.putExtra("beginTime", cal.getTimeInMillis());
                intent.putExtra("allDay", false);
                intent.putExtra("endTime", cal.getTimeInMillis() + 60 * 60 * 1000);
                //intent.putExtra("title", title);
                context.startActivity(intent);

            }
        });
        item.setText(episode);
        return convertView;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return episodeData.get(episodes.get(groupPosition)).size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return episodes.get(groupPosition);
    }

    @Override
    public int getGroupCount() {
        return episodes.size();
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {
        String episodeName = (String) getGroup(groupPosition);
        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.group_item,
                    null);
        }
        TextView item = (TextView) convertView.findViewById(R.id.episodeName);
        item.setTypeface(null, Typeface.BOLD);
        item.setText(episodeName.substring(0, 25));
        return convertView;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }

}

What's wrong? Thank you

lucgian84
  • 833
  • 4
  • 11
  • 29
  • Do get any error ? If that what it is ? What do you see in logcat once you tap on that row ? Post your `logcat`. Then, why have you not provided your layout ? Provide that. Trim your java code and keep only the essential parts. These are some basic ideas / common sense a person must have when posting a question in SO. Otherwise, no body is gonna read your questions. Remember, you are dependent on SO to get your answer and not the other way around. Just giving a piece of code, is not gonna get you anywhere . – The Dark Knight Jul 23 '13 at 13:29
  • How do you know `getChildView()` method is not called ? Have you debugged it ? I suggest you debug it in eclipse emulator by keeping a break point . – The Dark Knight Jul 23 '13 at 13:30
  • I retry to run my app but when I press on the row it shows nothing in logcat I know that this method is not called because I put a breakpoint in getChildView() and I saw that when I use the debug mode the app never stopped – lucgian84 Jul 23 '13 at 13:32
  • Have you debugged it ? – The Dark Knight Jul 23 '13 at 13:32
  • Sure I debugged it lot of time and I'm getting the same problem – lucgian84 Jul 23 '13 at 13:34
  • When you debug it , do you see the method `getChildView()` being called ? – The Dark Knight Jul 23 '13 at 13:35
  • Also, I put the breakpoint in the method getChildView(), I clicked on the icon to run the app in debug mode and I saw that the method getChildView() is not called. – lucgian84 Jul 23 '13 at 13:39
  • try returning `false` from `hasStableIds()`; – M-Wajeeh Jul 23 '13 at 13:40
  • @M-WaJeEh: same problem... – lucgian84 Jul 23 '13 at 13:42
  • well then your `getChildrenCount(int groupPos)` is returning 0. Check it ... if that's the case then your data popolation is wrong... – M-Wajeeh Jul 23 '13 at 13:44
  • I think you have not set `MAX_ITEMS_MEASURED` to the `ExpandableFaceList or whatever is the name of your adapter`. Look at this thread : http://stackoverflow.com/questions/15651288/getchildview-not-being-called?rq=1 It answers your question, i guess . – The Dark Knight Jul 23 '13 at 13:44
  • @M-WaJeEh: i tried and it returns 3 – lucgian84 Jul 23 '13 at 13:48
  • @TheDarkKnight: why in this code http://theopentutorials.com/tutorials/android/listview/android-expandable-list-view-example/ the adapter works right? – lucgian84 Jul 23 '13 at 13:53
  • My question precisely is , how do you know that piece of code in `the open tutorials` works ? Have you tried that piece ? I think that's what you have posted here . And it does not work .. – The Dark Knight Jul 23 '13 at 14:23
  • I tried it on the Galaxy S2 I'm using here and it works.... – lucgian84 Jul 23 '13 at 15:29
  • post your layout code... may be something is blocking your `ExpandableListView`. Can you see the click effect ? – M-Wajeeh Jul 23 '13 at 21:26
  • @M-WaJeEh: sorry for delay, when I click on the groupName I see that the arrow point up, when the view is loaded the arrow point in bottom. So I guess the phone understand my tap on the groupName – lucgian84 Jul 24 '13 at 09:22
  • Its getting interesting.. Can you post R.layout.child_item ? pls – M-Wajeeh Jul 24 '13 at 10:35
  • You can see my child_item.xml on this link: http://pastebin.com/FWXw8pDQ – lucgian84 Jul 24 '13 at 10:37
  • There's a news about my issue? – lucgian84 Jul 25 '13 at 09:12
  • 1
    I have exact same problem!!! what is solution?? – Big.Child Sep 03 '13 at 06:42
  • 1
    Same problem here.. any solution?? – Pandiri Deepak May 27 '14 at 12:37

0 Answers0