嗨,我正在尝试从 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();
}
}