我正在开发一个 Android 应用程序,但我遇到了可扩展列表的问题。我在网上找到了一个示例代码,并尝试根据我的情况对其进行调整。我试图将我的代码与我在网上找到的代码进行比较,它们看起来非常相似,但我的代码不起作用。当我尝试运行应用程序时,手机会正确加载带有可扩展列表的视图,它会显示组列表,但是当我点击要展开的行时,它不会显示任何内容。我的代码如下:
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;
}
}
怎么了?谢谢