{ // TODO Auto-generated constructor stub this.max_cod = max_cod; } @Override protected ArrayList doInBackground(String... max_cod) { try { HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLISEC); HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC); // HttpParams p = new BasicHttpParams(); p.setParameter("user", "1"); // Instantiate an HttpClient HttpClient httpclient = new DefaultHttpClient(p); String url = "http://10.0.2.2:80/clinica/" + "clinica.php?max_cod=" + this.max_cod + "&user=1&format=json"; HttpPost httppost = new HttpPost(url); // Instantiate a GET HTTP method try { Log.i(getClass().getSimpleName(), "send task - start"); // List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>( 2); nameValuePairs.add(new BasicNameValuePair("user", "1")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); ResponseHandler<String> responseHandler = new BasicResponseHandler(); Log.i(getClass().getSimpleName(), "funcionou ate"); String responseBody = httpclient.execute(httppost, responseHandler); Log.d("TESTE", responseBody); // Parse JSONObject json = new JSONObject(responseBody); JSONArray jArray = json.getJSONArray("posts"); ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>(); for (int i = 0; i < jArray.length(); i++) { HashMap<String, String> map = new HashMap<String, String>(); JSONObject e = jArray.getJSONObject(i); String s = e.getString("post"); JSONObject jObject = new JSONObject(s); map.put("codigo", jObject.getString("clin_func_empr_exam_codigo")); map.put("medico", jObject.getString("medi_nome")); map.put("func", jObject.getString("func_empr_nome")); map.put("exame", jObject.getString("exam_nome")); map.put("data", jObject .getString("clin_func_empr_exam_data_exame")); map.put("valor", jObject.getString("clin_func_empr_exam_valor")); mylist.add(map); } datasource.open(); HashMap<String, String> map_2 = new HashMap<String, String>(); for (Iterator<HashMap<String, String>> it = mylist .iterator(); it.hasNext();) { map_2 = it.next(); datasource.createLaudo(map_2.get("codigo"), map_2.get("medico"), map_2.get("func"), map_2.get("exame"), map_2.get("data"), map_2.get("valor")); } datasource.close(); return mylist; } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (Throwable t) { Log.i("Contactos", t.getMessage()); } return null; } @Override protected void onProgressUpdate(Integer... values) { // TODO Auto-generated method stub super.onProgressUpdate(values); } @SuppressLint("ParserError") @Override protected void onPostExecute(ArrayList result) { // TODO Auto-generated method stub super.onPostExecute(result); laudoList.clear(); datasource.open(); Cursor cursor = datasource.getLaudos(); for (int i = 0; i < cursor.getCount(); i++) { cursor.moveToPosition(i); Laudo contacto = new Laudo(cursor.getLong(0), cursor.getLong(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getString(5), cursor.getString(6)); laudoList.add(contacto); } adapter = new LaudoAdapter(LaudoActivity.this, laudoList); setListAdapter(adapter); adapter.notifyDataSetChanged(); datasource.close(); } }}/*******************************************************************************/> DbHelper.javaClasse responsavel pela conexao com o banco sqllite. package com.rober.clinica_laudo;import android.content.Context;import android.database.sqlite.SQLiteDatabase;import android.database.sqlite.SQLiteDatabase.CursorFactory;import android.database.sqlite.SQLiteOpenHelper;import android.util.Log;public class DbHelper extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 1; public static final String TABLE_NAME = "exames"; private static final String DATABASE_NAME = " clinica_laudo.db"; public static final String ID = "id"; public static final String CODIGO = "clin_func_empr_exam_codigo"; public static final String MEDICO = "medi_nome"; public static final String FUNCIONARIO = "func_empr_nome"; public static final String EXAME = "exam_nome"; public static final String DATA = "clin_func_empr_exam_data_exame"; public static final String VALOR = "clin_func_empr_exam_valor"; private static final String DATABASE_CREATE = "create table " + TABLE_NAME + "( " + ID + " integer primary key autoincrement, " + CODIGO + " integer not null, " + MEDICO + " text not null, " + FUNCIONARIO + " text not null, " + EXAME + " text not null, " + DATA + " text not null, " + VALOR + " text not null);"; public DbHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); //super() } @Override public void onCreate(SQLiteDatabase db) { db.execSQL(DATABASE_CREATE); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { Log.w(DbHelper.class.getName(), "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data"); db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME); onCreate(db); }}/********************************************************************************/>