在这里,我附上我的问题和代码的快照。
它只显示内容作为对象,但完美显示组名。
这个问题的快照在下面的链接中给出了这张图片
“ http://imageupload.org/?d=4DA941521”(快照)
=>我想要特定组名的子数据,但是我正在获取组名而不是子数据。
为此的代码
package com.bestdambikers;
import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class SectionedDemo extends ListActivity {
String strUrl = "http://192.168.5.10/ijoomer_development/index.php?option=com_ijoomer&plg_name=jomsocial&pview=user&ptask=field_list&userid=80&sessionid="+ConstantData.session_id+"&tmpl=component";
DetailBean dBean;
XmlParser parser;
ArrayList<Object> result;
List<DetailBean> list;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.header_main);
//dBean = new DetailBean();
parser = new XmlParser(strUrl, new DetailBean());
result = parser.ParseUrl("data", "group");
int r = result.size();
for(int i=0; i<result.size(); i++)
{
dBean = (DetailBean)result.get(i);
list=Arrays.asList(dBean);
Collections.shuffle(list);
adapter.addSection(dBean.group_name,
new ArrayAdapter<DetailBean>(this,
android.R.layout.simple_list_item_1,
list));
}
setListAdapter(adapter);
}
SectionedAdapter adapter=new SectionedAdapter() {
protected View getHeaderView(String caption, int index,
View convertView,
ViewGroup parent) {
TextView result=(TextView)convertView;
if (convertView==null) {
result=(TextView)getLayoutInflater()
.inflate(R.layout.header,
null);
}
result.setText(caption);
return(result);
}
};
}
DetailBean.java
public class DetailBean
{
public String data = null;
public String code = null;
public String fields = null;
public String group_name = null;
public String field = null;
public String id = null;
public String name = null;
public String value = null;
public String status = null;
public String required = null;
public String type = null;
public DetailBean()
{
this("","","","","","","","","","","");
}
public DetailBean(String data,String code,String fields, String group_name,String field, String id,String name,String value,String status,String required,String type)
{
this.data = data;
this.code = code;
this.fields = fields;
this.group_name = group_name;
this.field = field;
this.id = id;
this.name = name;
this.value = value;
this.status = status;
this.required = required;
this.type = type;
}
}
最佳答案
看起来您在String
方法的getHeaderView
参数中获得了caption
,该参数由detailBeanInstance.toString()进行。
您应该重写DetailBean类中的toString
方法以返回所需的内容。
这样的覆盖将是:
@Override
public String toString()
{
//You should populate this string with the data
//you need inside the TextView
return this.group_name + " " + this.data;
}
将上述方法放置在DetailBean类中,因此如下所示:
public class DetailBean
{
// You should use private members, and create getters and setters to them
public String data = null;
public String code = null;
public String fields = null;
public String group_name = null;
public String field = null;
public String id = null;
public String name = null;
public String value = null;
public String status = null;
public String required = null;
public String type = null;
public DetailBean()
{
this("", "", "", "", "", "", "", "", "", "", "");
}
public DetailBean(String data, String code, String fields,
String group_name, String field, String id, String name,
String value, String status, String required, String type)
{
this.data = data;
this.code = code;
this.fields = fields;
this.group_name = group_name;
this.field = field;
this.id = id;
this.name = name;
this.value = value;
this.status = status;
this.required = required;
this.type = type;
}
@Override
public String toString()
{
// You should populate this string with the data
// you need inside the TextView
return this.group_name + " " + this.data;
}
}