1

在使用 .net Web 服务单击列表中的项目后,我试图获取子文件夹。请建议。谢谢

 public void Treedata(){
            try {

                SoapObject datarequest = new SoapObject(NAMESPACE, TREEDATA_METHOD);

                datarequest.addProperty("UserID", 1);

                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                envelope.dotNet = true; 
                envelope.setOutputSoapObject(datarequest);

                Log.i("LoginDetail", "UserID " + 1);

                HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
                androidHttpTransport.debug = true;

                androidHttpTransport.call(SOAP_ACTION_TREEDATA, envelope);

                SoapObject dataresponse = (SoapObject)envelope.getResponse();

                Log.i("myData", dataresponse.toString());

                datalist = new String[dataresponse.getPropertyCount()];
                for(int i=0; i< dataresponse.getPropertyCount(); i++)

                datalist[i] = dataresponse.getProperty(i).toString();

                treedata = (ListView)findViewById(R.id.treedata);

                ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, datalist);

                treedata.setAdapter(adapter);

                treedata.setOnItemClickListener(new OnItemClickListener()
                {
                    @Override
                    public void onItemClick(AdapterView<?> arg0, View v,int position, long id) {
                        // TODO Auto-generated method stub

    // What to do here??? So that sub folders can get into next activity.       

                        Intent intent = new Intent(getApplicationContext(), Files_Folders_Activity.class);

                        startActivity(intent);

                    }   
                });
            }
        }

}

下一个活动:

public void subfolderTreedata(){
    try {

 SoapObject subfolderrequest = new SoapObject(NAMESPACE, SUBFOLDERTREEDATA_METHOD);

 subfolderrequest.addProperty("FolderID", 13002);    //13002 is folderID how can I get multiple Id Dynamically?

 subfolderrequest.addProperty("UserID", 1);

 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
 envelope.dotNet = true;
 envelope.setOutputSoapObject(subfolderrequest);

 HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
 androidHttpTransport.debug = true;

 androidHttpTransport.call(SOAP_ACTION_SUBFOLDERTREEDATA , envelope);

 SoapObject dataresponse = (SoapObject)envelope.getResponse();

 Log.i("subfoldersData", dataresponse.toString());

// if(UserID || FolderID == dataresponse){    //How to get dynamic userId and Password right now I am having static 1 for user password authentication, what to do for multiple authentication.

 subfolderslist = new String[dataresponse.getPropertyCount()];
 for(int i=0;i< dataresponse.getPropertyCount(); i++)

 subfolderslist[i] = dataresponse.getProperty(i).toString();
 subfolderstreedata = (ListView)findViewById(R.id.subfolderstreedata);

 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, subfolderslist);

 subfolderstreedata.setAdapter(adapter);

我的网络服务:

Host: ***.***.*.*
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/TreeDataSubFolder"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       
xmlns:xsd="http://www.w3.org/2001/XMLSchema"   
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<TreeDataSubFolder xmlns="http://tempuri.org/">
  <FolderID>string</FolderID>
  <UserId>string</UserId>
</TreeDataSubFolder>
 </soap:Body>
 </soap:Envelope>
  HTTP/1.1 200 OK
   Content-Type: text/xml; charset=utf-8
    Content-Length: length

   <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"                
      xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
        xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
       <TreeDataSubFolderResponse xmlns="http://tempuri.org/">
          <TreeDataSubFolderResult>
               <FileFolderDetails>
       <ID>int</ID>
       <Name>string</Name>
       <SubjectType>string</SubjectType>
     </FileFolderDetails>
     <FileFolderDetails>
      <ID>int</ID>
      <Name>string</Name>
      <SubjectType>string</SubjectType>
    </FileFolderDetails>
  </TreeDataSubFolderResult>
  </TreeDataSubFolderResponse>
 </soap:Body>
 </soap:Envelope>

我只是想确认如何同时发送 FOLDERID 和 USERID 以获取子文件夹并从 listitem 检索数据。

4

1 回答 1

0
Heres answer:


    public class TreeDataActivity extends Activity implements OnItemClickListener {

 private ListView datalist;

 private static final String NAMESPACE = "http://tempuri.org/";
 private static final String URL = "http://192.168.1.5/InterLogicsMobile/InterLogics.asmx";
 private static final String SOAP_ACTION = "http://tempuri.org/TreeData";
 private static final String TreeDataMethod = "TreeData";

 private String[] firstlist;
 String FolderID = null;
 String ID;
 String FolderName;
 String ParentID;
 String CreatedBy;
// List<IconSetter> rowItems;

// public static final Integer[] images = { R.drawable.folder_icon,};
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
        setContentView(R.layout.treedata);
        TreeData();
    }
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

        ID = (String) datalist.getItemAtPosition(arg2);
        //FolderName = (String) datalist.getItemAtPosition(arg2);

        Intent intent = new Intent(TreeDataActivity.this,TreeDataSubFolderActivity.class);
        intent.putExtra("ID",ID );
        //intent.putExtra("FolderName",FolderName );
        startActivity(intent);
    }


 private void TreeData() throws NullPointerException{

     try {
        SoapObject request = new SoapObject(NAMESPACE, TreeDataMethod);
        request.addProperty("UserID", 1);

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;  

        envelope.setOutputSoapObject(request);

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.debug = true;

        androidHttpTransport.call(SOAP_ACTION, envelope);

        SoapObject list = (SoapObject)envelope.getResponse();

        System.out.print(list);

        firstlist = new String[list.getPropertyCount()];

        for(int i=0;i< list.getPropertyCount();i++){
             /*rowItems = new ArrayList<IconSetter>();
             IconSetter item = new IconSetter(images[0],FolderName[1],ID[2]); 

             rowItems.add(item);*/
             SoapObject result = (SoapObject)list.getProperty(i);

             ID = result.getProperty(0).toString();
             FolderName = result.getProperty(1).toString();
             ParentID = result.getProperty(2).toString();
             CreatedBy = result.getProperty(3).toString();

             System.out.println(ID);
             System.out.println(FolderName);
             System.out.println(ParentID);
             System.out.println(CreatedBy);

             SoapPrimitive Record =(SoapPrimitive) result.getProperty(1);

             Log.i("Record", Record.toString());


           firstlist[i] = result.getPropertyAsString(0).toString();
          // firstlist[i] = result.getPropertyAsString(1).toString();

           datalist = (ListView) findViewById(R.id.first_list);

           ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, firstlist);

           datalist.setAdapter(adapter);

           datalist.setOnItemClickListener(this);
      }      
} 
        catch (Exception e) {           
            e.printStackTrace();
            Toast.makeText(getApplicationContext(), " NullPointerException " + e
                    + "Do Something", Toast.LENGTH_LONG).show();

        }finally{

        }
    }

}
于 2013-02-28T12:09:21.020 回答