List<String> FristList;
List<List<Nextcontent>> twoList;
private ExpandableListView exepand;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getJson();
exepand = (ExpandableListView)findViewById(R.id.exepand);
exepand.setAdapter(new MyAdaptere(MainActivity.this, FristList, twoList));
}
private void getJson() {
// TODO Auto-generated method stub
FristList=new ArrayList<String>();
twoList=new ArrayList<List<Nextcontent>>();
try {
Gson gson=new Gson();
Bean[] bean= gson.fromJson(new InputStreamReader(getAssets().open("an.json")),Bean[].class);
for (Bean bean2 : bean) {
FristList.add(bean2.classname);
twoList.add(bean2.nextcontent);
}
} catch (JsonSyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JsonIOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public class MyAdaptere extends BaseExpandableListAdapter {
public Context context;
public List<String> FristList;
public List<List<Nextcontent>> twoList;
private TextView text1;
public MyAdaptere(Context context,List<String> FristList,List<List<Nextcontent>> twoList){
this.context=context;
this.FristList=FristList;
this.twoList=twoList;
}
@Override
public int getChildrenCount(int arg0) {
// TODO Auto-generated method stub
if(twoList.get(arg0)!=null){
twoList.get(arg0).size();
return twoList.get(arg0).size();
}
return 0;
}
@Override
public int getGroupCount() {
// TODO Auto-generated method stub
return FristList.size();
}
@Override
public View getChildView(int arg0, int arg1, boolean arg2, View arg3,
ViewGroup arg4) {
// TODO Auto-generated method stub
View v = View.inflate(context, android.R.layout.simple_list_item_1, null);
text1 = (TextView)v.findViewById(android.R.id.text1);
if(twoList.get(arg0)!=null){
text1.setText(twoList.get(arg0).get(arg1).sclassname);
}
return v;
}
@Override
public View getGroupView(int arg0, boolean arg1, View arg2, ViewGroup arg3) {
// TODO Auto-generated method stub
View vv = View.inflate(context, android.R.layout.simple_list_item_1, null);
text1 = (TextView)vv.findViewById(android.R.id.text1);
text1.setText(FristList.get(arg0));
return vv;
}
@Override
public Object getChild(int arg0, int arg1) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getChildId(int arg0, int arg1) {
// TODO Auto-generated method stub
return 0;
}
@Override
public Object getGroup(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getGroupId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@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;
}
}