本文介绍了我想将数据集从JSON webservice返回到使用KSoap2的android ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述







我对Android更新。



我需要在KSoap2的帮助下使用JSON webservices从数据集中填充android列表视图。



我已经g目结舌但没有得到正确的解决方案或教程。



我试过这个例子但是抛出了错误



应用程序跟踪意外停止请再试一次-Force CLose



这是我的代码:



Hi


I'm fresher to Android.

I need to fill the android listview from dataset using JSON webservices with the help of KSoap2.

I goggled but didn't get proper solution or tutorial to it.

I tried this example but throws the error as

"the application tracking has stoppped unexpectedly please try again-Force CLose"

Here is my code:

SessionManager session;
				private static final String Soap_Action_JSONEXP="http://tempuri.org/Cargonet_tracking";
				private static final String METHOD_NAME_JSONEXP="Cargonet_tracking";
				private static final String NAMESPACEEXP="http://tempuri.org/";
				private static final String URL_jsEXP="http://192.168.1.126/testing/Cargo_Tracking.asmx/Cargonet?wsdl";
				private String TAG="Cargo";
				//String contentType = "application/json";
				ListView lv;
				private static String responseJSON;
				ProgressBar pg;
				Gson gson=new Gson();
				public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
				    session=new SessionManager(getActivity());
				    session.checkLogin();
				    View view=inflater.inflate(R.layout.activity_main,container,false);
				    return view;    
				}
				@Override
				public void onActivityCreated(Bundle savedInstanceState){
				    super.onActivityCreated(savedInstanceState);
				    lv=(ListView)getActivity().findViewById(R.id.listView1);
				    Thread cmdthredlista=new Thread(){
				    	
				    	
				    			
				        @Override
				    public void run(){
				            SoapObject cmdrequest=new SoapObject(NAMESPACEEXP,METHOD_NAME_JSONEXP);
				            System.out.println("requsest "+cmdrequest);
				            SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
				            envelope.dotNet=true;
				            envelope.setOutputSoapObject(cmdrequest);
				            HttpTransportSE ahttptransport=new HttpTransportSE(URL_jsEXP);
				            try {
				                ahttptransport.call(Soap_Action_JSONEXP,envelope);
				                //final SoapPrimitive response=(SoapPrimitive)envelope.getResponse();
				                SoapPrimitive response=(SoapPrimitive)envelope.getResponse();
				                responseJSON=response.toString();
				                getActivity().runOnUiThread(new Runnable() {
				                    @Override
				                    public void run() {
				                        try {
				                            String[] placelist;              
				                            placelist=gson.fromJson(responseJSON,String[].class);
				                            ArrayAdapter<String>cmdlistaadapteri;
				                            cmdlistaadapteri=new ArrayAdapter<String>(getActivity(),android.R.layout.activity_list_item,placelist);
				                            lv.setAdapter(cmdlistaadapteri);
				                        }
				                        catch (Exception e){
				                            e.printStackTrace();
				                            System.out.println("error ");
				                        }
				                    }
				                });
				            }
				            catch (Exception e){
				                e.printStackTrace();
				                System.out.println("error ");
				            }
				        }
				    };
				    cmdthredlista.start();
				}


	public String getTAG() {
		return TAG;
	}
	public void setTAG(String tAG) {
		TAG = tAG;
	}









任何人都可以帮助我。





Can any one please help me.

推荐答案

这篇关于我想将数据集从JSON webservice返回到使用KSoap2的android ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 13:39