显示标题相同但内容不同的数据

时间:2016-10-19 07:04:35

标签: android web-services view ksoap

如果我的数据库包含:

,请说
  

ID:1 |姓名:你好| Content1:sample1 | Content2:sample2

我开发了一个WSDL Web服务,其结果如下:

<name> hello </name>
<content1> sample1 </content1>
<content2> sample2 </content2>

我已使用KSOAP2从网络服务中读取数据。

String NAMESPACE = "blablabla";
String METHOD_NAME = "RequestDetails";
String SOAP_ACTION = NAMESPACE + METHOD_NAME;
String URL = "blablabla";

try {
    SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
    SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    soapEnvelope.dotNet = false;
    soapEnvelope.setOutputSoapObject(Request);
    HttpTransportSE transport = new HttpTransportSE(URL, 1000000);
    Log.i(TAG, "transport started and completed! ");
    transport.call(SOAP_ACTION, soapEnvelope);
    SoapObject resultString = (SoapObject) soapEnvelope.getResponse();
    constructor.setName(resultString.get("name").toString());
    constructor.setContent1(resultString.get("content1").toString());
    constructor.setContent2(resultString.get("content2").toString());
} catch(Exception e) {
    e.printStackTrace();
}
list.add(construct);

现在我把这个列表放到customAdapter中。然后,结果将是:

名称 内容1 内容2

我有什么地方可以让结果像?

名称 内容1 名称 内容2

因为它是一个列表视图,所以我希望有

名称 Content1是位置0。

名称 Content2是第1位。

2 个答案:

答案 0 :(得分:1)

您需要做的就是将listview_item_row设为 名称 内容1 名称 内容2

在向listview添加数据时只需检查名称和内容, 例如:

  

if(content2 == null)

不要为内容2添加名称

  

if(content2!= null)

然后jsonparsing就像

constructor.setName(resultString.get("name").toString());
constructor.setContent1(resultString.get("content1").toString());
constructor.setName(resultString.get("name").toString());
constructor.setContent2(resultString.get("content2").toString());

答案 1 :(得分:0)

尝试关注apprach

创建模型类

  

public class SampleModel {       字符串标题;       字符串内容;

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

public String getContent() {
    return content;
}

public void setContent(String content) {
    this.content = content;
}
     

}

     

public class SampleClass扩展AppCompatActivity {       @覆盖       protected void onCreate(@Nullable Bundle savedInstanceState){           super.onCreate(savedInstanceState);

    String NAMESPACE = "blablabla";
    String METHOD_NAME = "RequestDetails";
    String SOAP_ACTION = NAMESPACE + METHOD_NAME;
    String URL = "blablabla";

    List<SampleModel> arrayList = new ArrayList<>();
    try {
        SampleModel model;
        SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        soapEnvelope.dotNet = false;
        soapEnvelope.setOutputSoapObject(Request);
        HttpTransportSE transport = new HttpTransportSE(URL, 1000000);

        transport.call(SOAP_ACTION, soapEnvelope);
        SoapObject resultString = (SoapObject) soapEnvelope.getResponse();

        model = new SampleModel();
        model.setTitle(resultString.get("name").toString());
        model.setContent(resultString.get("content1").toString());
        arrayList.add(model);
        if (resultString.get("content2").toString() != null) {
            model = new SampleModel();
            model.setTitle(resultString.get("name").toString());
            model.setContent(resultString.get("content2").toString());
            arrayList.add(model);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    // here pass this arraylist to customListAdapeter

    //list.add(construct);


}
     

}