在我的 Android 应用程序中,我从 XML 文件中解析了数据并将它们放入某个对象中,现在我必须读取这些数据并将它们呈现在可扩展的列表视图中。我知道如何在可扩展列表视图中显示数据:我需要一个适配器,但要使用适配器,我首先需要存储在对象中的数据,那么如何从对象中读取数据?
编辑:在这里你可以看到我的适配器应该如何。
Myadapter.java
package it.lucgian84.adapter;
import it.lucgian84.models.Episode;
import it.lucgian84.models.Program;
import it.lucgian84.models.Programs;
import java.util.ArrayList;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
public class Myadapter extends BaseExpandableListAdapter {
private Context context;
private ArrayList<Program> programList;
public Myadapter(Context context, ArrayList<Program> programList) {
this.context = context;
this.programList = programList;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
Episode[] episodeList = programList.get(groupPosition).getEpisodes();
return episodeList.length;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
View view, ViewGroup parent) {
return null;
}
@Override
public int getChildrenCount(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public Object getGroup(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public int getGroupCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public long getGroupId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getGroupView(int arg0, boolean arg1, View arg2, ViewGroup arg3) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isChildSelectable(int arg0, int arg1) {
// TODO Auto-generated method stub
return false;
}
}
因此,在 Activity 中,我应该填充 ArrayList programList 以在我的适配器中使用。要填充 programList 我需要从我的对象中读取信息,如何填充 programList?
谢谢