-3

嗨,我正在尝试从 listview 获取子文件夹,我正在从 Web 服务获取列表,但是请任何人告诉我在单击 ItemClick 侦听器后如何获取子文件夹?我正在使用 .net 网络服务。

 public class LoginActivity extends Activity {

Button login;
TextView tv,result;
EditText user;
EditText pass;

 String Username,Password;
 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/CheckLogin";
 private static final String LoginMethod = "CheckLogin";

 String LoginResponse;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    setContentView(R.layout.login_activity);

    login = (Button) findViewById(R.id.btnLogin);
    tv = (TextView) findViewById(R.id.forget);

    tv.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            Intent i = new Intent(getApplicationContext(),ForgetActivity.class);
            startActivity(i);

        }

    });


    login.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            try{

                user=(EditText) findViewById(R.id.username);
                pass=(EditText) findViewById(R.id.password);

                Username= user.getText().toString();
                Password= pass.getText().toString();

            result = (TextView)findViewById(R.id.result);
            SoapObject request = new SoapObject(NAMESPACE, LoginMethod);

            request.addProperty("UserName", Username);
            request.addProperty("Password", Password);

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

            Log.i("LoginDetail", "Username " + Username + "Password " + Password);

            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            androidHttpTransport.debug = true;
            androidHttpTransport.call(SOAP_ACTION, envelope);

            SoapPrimitive response = (SoapPrimitive)envelope.getResponse();

                Log.i("myLogin", response.toString());
                System.out.println(response);

                LoginResponse = response.toString();

                if(LoginResponse==response.toString())
                {

                 Intent intent = new Intent(LoginActivity.this, Login.class);
                    startActivity(intent);

                }
                 else  
                {

                 Toast.makeText(LoginActivity.this, "Please check your Username and Password" , Toast.LENGTH_SHORT).show();

                }
            }

           catch (Exception e) {

            e.printStackTrace();
               Toast.makeText(getApplicationContext(), " Network Exception : " + e
                               + "Please check network connectivity.", Toast.LENGTH_LONG).show();
           } 
            }
        });
}

}

And 2nd Activity
public class Login 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[] list;
 ArrayList<String> folderList;
// private ArrayList<Item> items;
 String subfolder_id;

 private void TreeData() throws NullPointerException{

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

        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 response = (SoapObject)envelope.getResponse();

        System.out.print(response);
        list = new String[response.getPropertyCount()];
        Log.i("myList", response.toString());
        for(int i=0;i< response.getPropertyCount();i++){ 

           list[i] = response.getPropertyAsString(i).toString();
           Log.i("myData", response.toString());
           datalist = (ListView) findViewById(R.id.first_list);
           ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, list);
           datalist.setAdapter(adapter);
           datalist.setOnItemClickListener(this);
      }      
} 
        catch (Exception e) {           
            e.printStackTrace();
            Toast.makeText(getApplicationContext(), " NullPointerException " + e
                    + "Do Something", Toast.LENGTH_LONG).show();

        }finally{

        }
    }


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);
    TreeData();
}
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    Intent intent = new Intent(Login.this,TreeDataActivity.class);

    String subfolder_id = ((TextView) arg1.findViewById(R.id.subfolder_id)).getText().toString();
    intent.putExtra("subfolder_id", subfolder_id);
    startActivity(intent);
}

}

单击项目后单击没有得到任何进一步的列表。这是我的第三个活动

public class TreeDataActivity extends Activity {

 private ListView mylist;

 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/TreeDataSubFolder";
 private static final String TreeDataSubMethod = "TreeDataSubFolder";

 private String[] list;


 private void TreeDataSubFolder(){

     try {
        SoapObject request = new SoapObject(NAMESPACE, TreeDataSubMethod);

        request.addProperty("FolderID",13002);
        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 response = (SoapObject)envelope.getResponse();

        System.out.print(response);
        list = new String[response.getPropertyCount()];
        for(int i=0;i< response.getPropertyCount();i++){ 

           list[i] = response.getPropertyAsString(i).toString();

           Log.i("myData", response.toString());
           mylist = (ListView) findViewById(R.id.mylist);
           ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, list);
           mylist.setAdapter(adapter);


      }      
} 
        catch (Exception e) {           
            e.printStackTrace();
        }       
    }

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.treesubdata);

    TreeDataSubFolder();
}

}

4

1 回答 1

1
enter code here

package com.example.dms;

import java.util.ArrayList;
import java.util.List;

 import org.ksoap2.SoapEnvelope;
 import org.ksoap2.serialization.SoapObject;
 import org.ksoap2.serialization.SoapPrimitive;
 import org.ksoap2.serialization.SoapSerializationEnvelope;
 import org.ksoap2.transport.HttpTransportSE;

 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
 import android.os.StrictMode;
 import android.util.Log;
 import android.view.View;
 import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemClickListener;
 import android.widget.ArrayAdapter;
 import android.widget.ListView;
 import android.widget.Toast;

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

        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-28T11:55:02.727 回答