可扩展listview android json
您好,我正在尝试创建一个自定义的可扩展listview,但是适配器上的文档非常混乱和多样。像往常一样,我有一个hashmap来读取json数组,然后将它放在列表中。每个子级的组在最后一个位置的键“GRUPO”的同一数组中发送。有人能给我这个的适配器实现吗?json中的代码如下所示:可扩展listview android json,android,expandablelistview,expandablelistadapter,Android,Expandablelistview,Expandablelistadapter,您好,我正在尝试创建一个自定义的可扩展listview,但是适配器上的文档非常混乱和多样。像往常一样,我有一个hashmap来读取json数组,然后将它放在列表中。每个子级的组在最后一个位置的键“GRUPO”的同一数组中发送。有人能给我这个的适配器实现吗?json中的代码如下所示: if (tipopergunta.contentEquals("BOOLEANO") || tipopergunta.contentEquals("ESCMULTIPLA") || tip
if (tipopergunta.contentEquals("BOOLEANO") || tipopergunta.contentEquals("ESCMULTIPLA") || tipopergunta.contentEquals("ESCUNICA")){
HashMap<String,String> childdados = new HashMap<String,String>();
childdados.put("GRUPO", "Dados");
childdados.put("TIPOPERGUNTA", tipopergunta);
childdados.put("PERGUNTA", pergunta);
childdados.put("BREVEDESIGNACAO", brevedesc);
childdados.put("ESTADO",estado);
childdados.put("INSTRUCOES",instrucoes);
childdados.put("IDPERGUNTA",idpergunta);
Log.d("childdados",""+childdados.toString());
list.add(childdados);
}
if (tipopergunta.contentEquals("OPINIAO")){
HashMap<String,String> childdados = new HashMap<String,String>();
childdados.put("GRUPO", "Opinião");
childdados.put("TIPOPERGUNTA", tipopergunta);
childdados.put("PERGUNTA", pergunta);
childdados.put("BREVEDESIGNACAO", brevedesc);
childdados.put("ESTADO",estado);
childdados.put("INSTRUCOES",instrucoes);
childdados.put("IDPERGUNTA",idpergunta);
Log.d("opiniaolist",childdados.toString());
list.add(childdados);
}
if (tipopergunta.contentEquals("FOTOGRAFIA")){
HashMap<String,String> childdados = new HashMap<String,String>();
childdados.put("GRUPO", "Fotografia");
childdados.put("TIPOPERGUNTA", tipopergunta);
childdados.put("PERGUNTA", pergunta);
childdados.put("BREVEDESIGNACAO", brevedesc);
childdados.put("ESTADO",estado);
childdados.put("INSTRUCOES",instrucoes);
childdados.put("IDPERGUNTA",idpergunta);
Log.d("fotolist",childdados.toString());
list.add(childdados);
}
if(tipopergunta.contentEquals(“BOOLEANO”)| | tipopergunta.contentEquals(“escumpula”)| | tipopergunta.contentEquals(“ESCUNICA”)){
HashMap childdados=新HashMap();
childdados.put(“GRUPO”、“Dados”);
childdados.put(“蒂波佩尔贡塔”,蒂波佩尔贡塔);
childdados.put(“PERGUNTA”,PERGUNTA);
childdados.put(“brevedesignaco”,brevedesc);
childdados.put(“ESTADO”,ESTADO);
childdados.put(“指令”,指令);
childdados.put(“Idergunta”,Idergunta);
Log.d(“childdados”,“”+childdados.toString());
列表。添加(childdados);
}
if(tipopergunta.contentEquals(“OPINIAO”)){
HashMap childdados=新HashMap();
childdados.put(“GRUPO”、“Opinião”);
childdados.put(“蒂波佩尔贡塔”,蒂波佩尔贡塔);
childdados.put(“PERGUNTA”,PERGUNTA);
childdados.put(“brevedesignaco”,brevedesc);
childdados.put(“ESTADO”,ESTADO);
childdados.put(“指令”,指令);
childdados.put(“Idergunta”,Idergunta);
Log.d(“opiniaolist”,childdados.toString());
列表。添加(childdados);
}
if(tipopergunta.contentEquals(“FOTOGRAFIA”)){
HashMap childdados=新HashMap();
childdados.put(“GRUPO”、“Fotografia”);
childdados.put(“蒂波佩尔贡塔”,蒂波佩尔贡塔);
childdados.put(“PERGUNTA”,PERGUNTA);
childdados.put(“brevedesignaco”,brevedesc);
childdados.put(“ESTADO”,ESTADO);
childdados.put(“指令”,指令);
childdados.put(“Idergunta”,Idergunta);
Log.d(“fotolist”,childdados.toString());
列表。添加(childdados);
}
帮助我理解了可扩展列表视图适配器
在可扩展列表视图中,您始终具有父级和子级。单击父对象时,您会看到其子对象
因此,适配器主要需要3样东西。
父母的名单。
子项列表(例如,可以是数组的数组)
如何画孩子,如何画父母
您应该有一个父数组:String[]parents={“parent1”,parent2”);
还有一个childern数组,每个数组都是一个父对象的子对象
String [][] children = {{child_A_Parent1, child_B_Parent1}, {child_A_Parent2, child_B_parent2}};
在方法getGroup上,应返回给定行所需的父级:
public Object getGroup(int groupPosition) {
return parents[groupPosition];
}
在方法getChild上,应返回所需的子对象:
public Object getChild(int groupPosition, int childPosition) {
return children[groupPosition][childPosition];
}
在方法getChildView()上,您应该扩展所需的布局(例如,带有textview的xml),并使用相应的子级设置文本。请注意,在这里,您不必担心它已传递给参数的子级:
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
//inflate a the layout and get the text view
tv.setText(children[grouposition][childPosition];
..}
对于父方法也可以这样说:
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
//inflate a the layout and get the text view
tvParent.setText(parents[groupPosition];
}
您可以为父级和子级设置各种布局。只需使用充气器从布局文件夹中充气xml。然后使用资源id用小部件填充视图
希望这有助于您将数据适应此代码段。帮助我理解可扩展列表视图适配器
在可扩展列表视图中,您始终有父项和子项。单击父项时,您将看到其子项
因此,适配器主要需要3样东西。
父母的名单。
子项列表(例如,可以是数组的数组)
如何画孩子,如何画父母
您应该有一个父数组:String[]parents={“parent1”,parent2”);
还有一个childern数组,每个数组都是一个父对象的子对象
String [][] children = {{child_A_Parent1, child_B_Parent1}, {child_A_Parent2, child_B_parent2}};
在方法getGroup上,应返回给定行所需的父级:
public Object getGroup(int groupPosition) {
return parents[groupPosition];
}
在方法getChild上,应返回所需的子对象:
public Object getChild(int groupPosition, int childPosition) {
return children[groupPosition][childPosition];
}
在方法getChildView()上,您应该扩展所需的布局(例如,带有textview的xml),并使用相应的子级设置文本。请注意,在这里,您不必担心它已传递给参数的子级:
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
//inflate a the layout and get the text view
tv.setText(children[grouposition][childPosition];
..}
对于父方法也可以这样说:
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
//inflate a the layout and get the text view
tvParent.setText(parents[groupPosition];
}
您可以为父级和子级设置各种布局。只需使用充气器从布局文件夹中充气xml。然后使用资源id用小部件填充视图
希望这有助于您将数据适配到此片段。我似乎仍然不明白。我可以将我在图像适配器上获得的信息放在这里,我不知道如何在适配器上实现它。我尝试解释每种方法。看看它是否对您有帮助。我似乎仍然不明白。我可以将我在图像适配器上获得的信息放在这里,我知道我不知道如何在适配器上实现它。我试图解释每个方法。看看它是否对您有帮助。