示出了对象,而不是串 [英] showing the object instead of string

查看:132
本文介绍了示出了对象,而不是串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面我为我的连接​​问题,code表示的单元。
它显示我只是内容对象,但节目组名完美。
这个问题的单元被赋予在下面​​的链接只是去throught这一形象

http://imageupload.org/?d=4DA941521(快照)

=>我要特别组名儿童的数据,但我m到处组名,而不是孩子的数据。

code此

 包com.bestdambikers;
进口android.app.ListActivity;
进口android.content.Context;
进口android.os.Bundle;
进口android.view.View;
进口android.view.ViewGroup;
进口android.widget.AdapterView;
进口android.widget.ArrayAdapter;
进口android.widget.ListView;
进口android.widget.TextView;进口的java.util.ArrayList;
进口java.util.Arrays中;
进口java.util.Collections中;
进口的java.util.List;公共类SectionedDemo扩展ListActivity {
    字符串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的解析器;
      ArrayList的<对象>结果;
      清单< D​​etailBean>清单;    @覆盖
    公共无效的onCreate(捆绑冰柱){
        super.onCreate(冰柱);
        的setContentView(R.layout.header_main);        // dBean =新DetailBean();
        分析器=新XmlParser的(strUrl,新DetailBean());
        结果= parser.ParseUrl(数据,集团);
        INT R = result.size();        的for(int i = 0; I< result.size();我++)
        {            dBean =(DetailBean)result.get(ⅰ);
            清单= Arrays.asList(dBean);
            Collections.shuffle(名单);
            adapter.addSection(dBean.group_name,
                新ArrayAdapter< D​​etailBean>(这一点,
                        android.R.layout.simple_list_item_1,
                        列表));
        }
        setListAdapter(适配器);
    }    SectionedAdapter适配器=新SectionedAdapter(){
        受保护的视图getHeaderView(字符串标题,INT指数,
                查看convertView,
                父母的ViewGroup){
            TextView的结果=(TextView中)convertView;            如果(convertView == NULL){
                结果=(TextView中)getLayoutInflater()
                .inflate(R.layout.header,
                        空值);
            }            result.setText(标题);            返回(结果);
        }
    };
}

DetailBean.java

 公共类DetailBean
{
    公共字符串数据= NULL;
    公共字符串code = NULL;
    公共字符串字段= NULL;
    公共字符串组名= NULL;
    公共字符串场= NULL;
    公共字符串ID = NULL;
    公共字符串名称= NULL;
    公共字符串值= NULL;
    公共字符串状态= NULL;
    公共字符串所需= NULL;
    公共字符串类型= NULL;    公共DetailBean()
    {
        这个(,,,,,,,,,,);
    }    公共DetailBean(字符串数据,字符串code,字符串字段GROUP_NAME字符串,字符串字段,字符型,字符串名称,字符串值,字符串的状态,需要字符串,字符串型)
    {
        this.data =数据;
        这code = code;
        this.fields =领域;
        this.group_name =组名;
        this.field =领域;
        this.id = ID;
        this.name =名称;
        THIS.VALUE =价值;
        this.status =状态;
        this.required =必需的;
        this.type =类型;
    }}


解决方案

它看起来像你得到一个字符串 getHeaderView 由detailBeanInstance.toString制作方法的标题参数()。

您应重写的toString 方法DetailBean类返回你想要什么。

这样的覆盖将是:

  @覆盖
公共字符串的toString()
{
    //你应该填充该字符串数据
    //你需要的TextView的内
    返回this.group_name ++ this.data;
}

将上面的方法你DetailBean类中,所以它看起来像:

 公共类DetailBean
{
    //您应该使用私有成员,并创建getter和setter他们
    公共字符串数据= NULL;
    公共字符串code = NULL;
    公共字符串字段= NULL;
    公共字符串组名= NULL;
    公共字符串场= NULL;
    公共字符串ID = NULL;
    公共字符串名称= NULL;
    公共字符串值= NULL;
    公共字符串状态= NULL;
    公共字符串所需= NULL;
    公共字符串类型= NULL;    公共DetailBean()
    {
        这个(, , , , , , , , , , );
    }    公共DetailBean(字符串数据,字符串code,字符串字段
            GROUP_NAME字符串,字符串字段,字符型,字符串名称,
            字符串值,字符串的状态,需要字符串,字符串型)
    {
        this.data =数据;
        这code = code;
        this.fields =领域;
        this.group_name =组名;
        this.field =领域;
        this.id = ID;
        this.name =名称;
        THIS.VALUE =价值;
        this.status =状态;
        this.required =必需的;
        this.type =类型;
    }    @覆盖
    公共字符串的toString()
    {
        //你应该填充该字符串数据
        //你需要的TextView的内
        返回this.group_name ++ this.data;
    }
}

Here i m attaching snap of my problem and code for that. it shows me only the content as object but shows groupname perfectly. the snap for this problem is given in as below link just go throught this image

"http://imageupload.org/?d=4DA941521"(snapshot)

=> I want child data of particular groupname but i m getting groupname instead of child data.

code for this

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;
    }

}

解决方案

It looks like you are getting a String in your getHeaderView method's caption parameter that is made by detailBeanInstance.toString().

You should override the toString method in DetailBean class to return what you want.

Such an override would be:

@Override
public String toString()
{
    //You should populate this string with the data 
    //you need inside the TextView
    return this.group_name + " " + this.data;
}

Place the method above inside your DetailBean class, so it would look like:

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;
    }
}

这篇关于示出了对象,而不是串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆