0

在我的应用程序中,我遇到了一个无法解决的问题:我正在使用可扩展列表,但它不起作用,我也不知道为什么。我的适配器是这样的:

可扩展列表适配器

import it.bitmama.interactv4.R;

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

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

public class ExpandableListAdapter extends BaseExpandableListAdapter {

    private Activity context;
    private Map<String, List<String>> episodeData;
    private List<String> episodes;

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

    public Object getChild(int groupPosition, int childPosition) {
        Log.d("getChild", "" + episodeData.get(episodes.get(groupPosition)).get(childPosition));
        return episodeData.get(episodes.get(groupPosition)).get(childPosition);
    }

    public long getChildId(int groupPosition, int childPosition) {
        Log.d("getChildId", "" + childPosition);
        return childPosition;
    }

    public View getChildView(final int groupPosition, final int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {
        Log.d("getChildView", "getChildView");
        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;
    }

    public int getChildrenCount(int groupPosition) {
        Log.d("getChildView", "" + episodeData.get(episodes.get(groupPosition)).size());
        return episodeData.get(episodes.get(groupPosition)).size();
    }

    public Object getGroup(int groupPosition) {
        Log.d("DATI", "" + episodeData);
        Log.d("getGroup", "" + episodes.get(groupPosition));
        return episodes.get(groupPosition);
    }

    public int getGroupCount() {
        Log.d("getGroupCount", "" + episodes.size());
        return episodes.size();
    }

    public long getGroupId(int groupPosition) {
        Log.d("getGroupId", "" +groupPosition);
        return groupPosition;
    }

    public View getGroupView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {
        Log.d("getGroupView", "getGroupView");
        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;
    }

    public boolean hasStableIds() {
        return true;
    }

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

当我尝试调试它时,我发现它从不调用 getChildView 方法,我不知道为什么。在 episodeData 我有这个数据(查看链接)http://postimg.org/image/h1m1gzqzx/它向我展示了这个http://postimg.org/image/nv37tk7ab/ 为什么它不起作用?我做错了什么?我希望你能帮我解决这个问题谢谢

4

0 回答 0