【发布时间】:2014-06-17 16:08:01
【问题描述】:
我从 SOAP Web 服务获取 SOAP WSDL 的 GetVehicles 方法,并在单击 Button 事件时调用 GetVehicles 导致 TextView。 我的 xml 中有一个按钮和一个 TextView。
当我运行程序时,数据显示在 textview 中,我想在 Sqlite 数据库中存储或保存 TextView 中显示的结果? 我创建了扩展 SQLiteOpenHelper 的 DatabaseHandler 类。 我正在传递这两个用于 id 和 name 的参数,
这是我的代码:
public class GetVehiclesActivity extends Activity {
private static String SOAP_ACTION = "http://tempuri.org/GetServerVehicles";
private static String NAMESPACE = "http://tempuri.org/";
private static String METHOD_NAME = "GetServerVehicles";
private static String URL = "http://favouritehatfield.co.uk/Service1.asmx?";
private TextView txtV_vehicles;
private long clientid=46;
private String response;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.getvehicles);
/** Show Toast at the Start of Activity... **/
Toast.makeText(this, "WELCOME to GET VEHICLES ACTIVITY..", 1).show();
txtV_vehicles = (TextView) findViewById(R.id.txtV_lbl_vehicles);
DatabaseHandler db = new DatabaseHandler(this);
}//End onCreate()
private class vehiclesAsyncTask extends AsyncTask<Void, Void, Void>{
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
txtV_vehicles.setText(response);
}//End onPostExecute()
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
}//End onPreExecute()
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
SoapObject getVehiclesRequest = new SoapObject(NAMESPACE,METHOD_NAME);
// add paramaters and values
PropertyInfo pi = new PropertyInfo();
pi.setName("defaultclientId");
pi.type= PropertyInfo.LONG_CLASS;
getVehiclesRequest.addProperty(pi,46);
PropertyInfo pi2 = new PropertyInfo();
pi2.setName("hashKey");
pi2.type= PropertyInfo.STRING_CLASS;
getVehiclesRequest.addProperty(pi2,"464321orue");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.setOutputSoapObject(getVehiclesRequest);
envelope.dotNet = true;
HttpTransportSE httpTransport = new HttpTransportSE(URL);
//httpTransport.debug = true;
try {
httpTransport.call(SOAP_ACTION, envelope);
} catch (HttpResponseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
SoapPrimitive result = (SoapPrimitive) envelope.getResponse();
response = result.toString();
} catch (SoapFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}//End doInBackground
}// End vehiclesAsyncTask
/** Called when the user clicks the GetVehicles button */
public void getVehicle(View v) {
String str = "You have clicked GetVehicles ...";
Toast.makeText(this, str, 0).show();
vehiclesAsyncTask vehiclesRequest = new vehiclesAsyncTask();
vehiclesRequest.execute();
//
}//End getVehicle()
/** Called when the user clicks the SAVEDATA button I want this buton to save the TextView result in SQLite Database*/
/** Called when the user clicks the SAVEDATA button */
public void saveData(View v) {
String str = "Save DAta Button Clicked ...";
Toast.makeText(this, str, 0).show();
String s1 = txtV_vehicles.getText().toString();
Objdbhandler.saveVehicles(s1, s1, s1, s1, s1);
// Objdbhandler.saveVehicles(Name, TotalPassengers, TotalHandLuggages, TotalLugages, SortOderNo)
}//End saveData(...) Method
}//结束类GetVehiclesActivity
我搜索了很多,但找不到任何线索。 我怎样才能做到这一点?
【问题讨论】:
-
我传递了这两个参数,分别是 id 和 name,PropertyInfo pi = new PropertyInfo(); pi.setName("defaultclientId"); // pi.setValue(clientid); pi.type=PropertyInfo.LONG_CLASS; getVehiclesRequest.addProperty(pi,46); PropertyInfo pi2 = new PropertyInfo(); pi2.setName("hashKey"); // pi.setValue(clientid); pi2.type=PropertyInfo.STRING_CLASS; getVehiclesRequest.addProperty(pi2,"464321orue");
-
您是否尝试插入 2 个不同的数据库,因为我可以在
db.insert()命令中看到“defaultclientId”和“mensagens”? -
日志猫有异常吗?
-
no defaultclientid 和 hashcode 是我的两个参数。 menagens 被评论不应该被阅读。此数据来自 SOAP Web 服务
标签: android web-services soap android-sqlite arrays