2016-10-19 4 views
0

Lassen Sie uns sagen, wenn ich eine Datenbank, die folgendes enthalten:Anzeigedaten mit dem gleichen Titel, aber unterschiedliche Inhalte

ID: 1 | Name: Hallo | Inhalt1: Probe1 | Content2: sample2

Und ich habe eine WSDL-Webservice, die das Ergebnis wie dieses entwickelt:

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

I KSOAP2 verwendet haben die Daten aus dem Webservice zu lesen.

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

Und jetzt habe ich diese Liste in einen customAdapter. Dann wird das Ergebnis sein wie:

Namen Content1 Content2

Gibt es irgendwo für mich das Ergebnis aussehen zu machen?

Namen Content1 Namen Content2

Da es eine Listenansicht ist, so wünsche ich

Namen haben Content1 ist die Position 0.

Namen Content2 ist Position 1.

Antwort

1

alles, was Sie tun müssen, ist listview_item_row als Name content1 Name content2

und während Daten zur Listenansicht Hinzufügen nur Namen und Inhalt überprüfen, ab:

if (content2 == null)

fügen Sie keinen Namen für Inhalt 2

if (Inhalt2!= Null)

dann wie

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

hallo @Rites. Haben Sie die gleiche Position in der Listenansicht? weil ich möchte, dass ich in einer anderen Position bin. wie Name content1 ist position0 und Name content2 ist positioni1 –

0

Versuch folgende sein jsonparsing apprach

Modellklasse erstellen

public class SampleModel { String title; Zeichenfolge Inhalt;

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 Sample AppCompatActivity erstreckt { @Override 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); 


} 

}

+0

hmmm das sieht gut aus. werde es bald versuchen –

Verwandte Themen