Note that there are some explanatory texts on larger screens.

plurals
  1. POwant to print group name and its child data
    primarykey
    data
    text
    <p>here</p> <p>i am trying to print dynamically particular group name and its child data like header and its contents .</p> <p>but i m able to pring group name in header that is no issue.</p> <p>But the problem is, i m also getting the group name instead of child contents </p> <p><a href="https://stackoverflow.com/questions/5685084/showing-the-object-instead-of-string/5685113#5685113">link to my code</a></p> <p>here is the code: SectionDemo.java</p> <pre><code>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&amp;plg_name=jomsocial&amp;pview=user&amp;ptask=field_list&amp;userid=80&amp;sessionid="+ConstantData.session_id+"&amp;tmpl=component"; DetailBean dBean; XmlParser parser; ArrayList&lt;Object&gt; result; List&lt;DetailBean&gt; 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&lt;result.size(); i++) { dBean = (DetailBean)result.get(i); list=Arrays.asList(dBean); Collections.shuffle(list); adapter.addSection(dBean.group_name, new ArrayAdapter&lt;DetailBean&gt;(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); } }; } </code></pre> <p>and code for <code>DetailBean.java</code></p> <pre><code>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; } @Override public String toString() { // You should populate this string with the data // you need inside the TextView return this.group_name + " " + this.data; } } </code></pre> <p>xml file which i want to parse</p> <pre><code>&lt;data&gt; &lt;code&gt;1&lt;/code&gt; &lt;fields&gt; &lt;group&gt; &lt;group_name&gt;Basic Information&lt;/group_name&gt; &lt;field&gt; &lt;id&gt;2&lt;/id&gt; &lt;name&gt;Gender&lt;/name&gt; &lt;value&gt;female&lt;/value&gt; &lt;required&gt;1&lt;/required&gt; &lt;type&gt;select&lt;/type&gt; &lt;/field&gt; &lt;field&gt; &lt;id&gt;3&lt;/id&gt; &lt;name&gt;Birthday&lt;/name&gt; &lt;value&gt;05-06-2011&lt;/value&gt; &lt;required&gt;1&lt;/required&gt; &lt;type&gt;date&lt;/type&gt; &lt;/field&gt; &lt;field&gt; &lt;id&gt;4&lt;/id&gt; &lt;name&gt;About me&lt;/name&gt; &lt;value&gt;Well meet me u will come to know&lt;/value&gt; &lt;required&gt;1&lt;/required&gt; &lt;type&gt;textarea&lt;/type&gt; &lt;/field&gt; &lt;/group&gt; &lt;group&gt; &lt;group_name&gt;Contact Information&lt;/group_name&gt; &lt;field&gt; &lt;id&gt;6&lt;/id&gt; &lt;name&gt;Mobile phone&lt;/name&gt; &lt;value&gt;5555555555&lt;/value&gt; &lt;required&gt;0&lt;/required&gt; &lt;type&gt;text&lt;/type&gt; &lt;/field&gt; &lt;field&gt; &lt;id&gt;7&lt;/id&gt; &lt;name&gt;Land phone&lt;/name&gt; &lt;value&gt;6666666666&lt;/value&gt; &lt;required&gt;0&lt;/required&gt; &lt;type&gt;text&lt;/type&gt; &lt;/field&gt; &lt;field&gt; &lt;id&gt;8&lt;/id&gt; &lt;name&gt;Address&lt;/name&gt; &lt;value&gt;Tassel global&lt;/value&gt; &lt;required&gt;1&lt;/required&gt; &lt;type&gt;textarea&lt;/type&gt; &lt;/field&gt; &lt;field&gt; &lt;id&gt;9&lt;/id&gt; &lt;name&gt;State&lt;/name&gt; &lt;value&gt;Gujarat&lt;/value&gt; &lt;required&gt;1&lt;/required&gt; &lt;type&gt;text&lt;/type&gt; &lt;/field&gt; &lt;field&gt; &lt;id&gt;10&lt;/id&gt; &lt;name&gt;City / Town&lt;/name&gt; &lt;value&gt;Ahmedabad&lt;/value&gt; &lt;required&gt;1&lt;/required&gt; &lt;type&gt;text&lt;/type&gt; &lt;/field&gt; &lt;field&gt; &lt;id&gt;11&lt;/id&gt; &lt;name&gt;Country&lt;/name&gt; &lt;value&gt;India&lt;/value&gt; &lt;required&gt;1&lt;/required&gt; &lt;type&gt;country&lt;/type&gt; &lt;/field&gt; &lt;field&gt; &lt;id&gt;12&lt;/id&gt; &lt;name&gt;Website&lt;/name&gt; &lt;value&gt;http://www.google.com&lt;/value&gt; &lt;required&gt;1&lt;/required&gt; &lt;type&gt;url&lt;/type&gt; &lt;/field&gt; &lt;/group&gt; &lt;group&gt; &lt;group_name&gt;Education&lt;/group_name&gt; &lt;field&gt; &lt;id&gt;14&lt;/id&gt; &lt;name&gt;College / University&lt;/name&gt; &lt;value&gt;California university&lt;/value&gt; &lt;required&gt;1&lt;/required&gt; &lt;type&gt;text&lt;/type&gt; &lt;/field&gt; &lt;field&gt; &lt;id&gt;15&lt;/id&gt; &lt;name&gt;Graduation Year&lt;/name&gt; &lt;value&gt;2010&lt;/value&gt; &lt;required&gt;1&lt;/required&gt; &lt;type&gt;text&lt;/type&gt; &lt;/field&gt; &lt;/group&gt; &lt;/fields&gt; &lt;/data&gt; </code></pre> <p><strong>XmlParser.java</strong></p> <pre><code>import java.io.InputStream; import java.net.URL; import java.util.ArrayList; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; import android.util.Log; public class XmlParser extends DefaultHandler { public String RootElement; public String RecordElement; public InputStream in; public Object mainObj; public Object newObj; public boolean inProcess; public String xmlURL; public ArrayList&lt;Object&gt; Records = null; private final String TAG = "XmlParser"; StringBuffer buffer = new StringBuffer(); String elementName; String elementValue; public XmlParser(final InputStream is, final Object tempObj) { this.in = is; this.mainObj = tempObj; Log.i("Object value", "" + this.mainObj); this.inProcess = false; } public XmlParser(final String strURL, final Object tempObj) { this.xmlURL = strURL; this.mainObj = tempObj; this.inProcess = false; } public ArrayList&lt;Object&gt; ParseUrl(final String rootElement, final String recordElement) { this.RootElement = rootElement; Log.i("RootElement", this.RootElement); this.RecordElement = recordElement; Log.i("RecordElement", this.RecordElement); try { final URL sourceUrl = new URL(this.xmlURL); Log.d("URl", this.xmlURL); final SAXParserFactory spf = SAXParserFactory.newInstance(); final SAXParser sp = spf.newSAXParser(); final XMLReader reader = sp.getXMLReader(); reader.setContentHandler(this); reader.parse(new InputSource(sourceUrl.openStream())); } catch (final Exception e) { e.printStackTrace(); return null; } return this.Records; } public ArrayList&lt;Object&gt; parse(final String rootElement, final String recordElement) { this.RootElement = rootElement; this.RecordElement = recordElement; Log.i("Root Element", "" + this.RootElement); Log.i("Record Element", "" + this.RecordElement); try { final SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); parser.parse(this.in, this); } catch (final Exception e) { e.printStackTrace(); return null; } return this.Records; } @Override public void startElement(final String Uri, final String localName, final String qName, final Attributes attributes)throws SAXException { Log.d("URl", this.xmlURL); this.elementValue = ""; Log.i("IN STARTELEMENT", "" + this.elementValue); if (localName.length() &gt; 0) { Log.i("Local Name Length", "" + localName.length()); Log.i("LocalName", "" + localName); if (localName.equalsIgnoreCase(this.RootElement)) { this.Records = new ArrayList&lt;Object&gt;(); Log.i("Root element", "" + this.RootElement); Log.i("Records", "" + this.Records); } else if (localName.equalsIgnoreCase(this.RecordElement)) { this.newObj = ClassUtils.newObject(this.mainObj); Log.i("Main Object", "" + this.mainObj); Log.i("Record element", "" + this.RecordElement); ClassUtils.objectMapping(this.newObj, localName, this.elementValue); Log.i("Element Value", "" + this.elementValue); this.inProcess = true; } } } @Override public void characters(final char[] ch, final int start, final int length) throws SAXException { this.elementValue += new String(ch, start, length).trim(); Log.i("CHARACTERS VALUE", "" + this.elementValue); } @Override public void endElement(final String Uri, final String localName, final String qName) throws SAXException { if (localName.equalsIgnoreCase(this.RecordElement)) { this.Records.add(this.newObj); this.inProcess = false; } else if (this.inProcess) ClassUtils.objectMapping(this.newObj, localName, this.elementValue); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload