Jogi Asad Ali

Jogi Asad Ali

  • NA
  • 10
  • 2.4k

how to save textview data into sqlite in android

Jun 18 2014 3:37 AM

I am getting GetVehicles method of SOAP WSDL from SOAP web services and call that GetVehicles result in TextView when clicking on a Button event. there is one button and one TextView in my xml.

when I run program the data is shown in textview , I want to store or save that result shown in TextView in Sqlite database?. I have created DatabaseHandler class extending SQLiteOpenHelper. I am passing these two parameters which are for id and name,

HERE IS MY CODE:

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 */ public void saveData(View v) { /*         ContentValues cValues = new ContentValues();         cValues.put("defaultclientId", "clientidclientid");         //db.insert("defaultclientId", null, cValues);         */ String s1 = txtV_vehicles.getText().toString(); // call saveVehicles from DatabaseHandler in SaveData Button //saveVehicles }//End saveData() }//End class  GetVehiclesActivity
I have searched a lot but couldn't find any clue. How can I do that?