Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.lleguebien.prototipo1;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.ArrayList;
- import java.util.List;
- import org.apache.http.HttpEntity;
- import org.apache.http.HttpResponse;
- import org.apache.http.client.ClientProtocolException;
- import org.apache.http.client.HttpClient;
- import org.apache.http.client.methods.HttpGet;
- import org.apache.http.impl.client.DefaultHttpClient;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import android.app.Activity;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.support.v4.app.FragmentActivity;
- import android.util.Log;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.Window;
- import android.widget.ArrayAdapter;
- import android.widget.ListView;
- import android.widget.Spinner;
- import android.widget.Toast;
- public class CheckIn extends FragmentActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- Log.i("boton", "Llegue");
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
- setContentView(R.layout.check_in);
- String patente = this.getIntent().getExtras().getString("patente");
- new LlenarLV().execute(patente);
- }
- private class LlenarLV extends AsyncTask<String, Void, JSONObject>{
- @Override
- protected JSONObject doInBackground(String... patente) {
- Log.i("PruebasBla", "Iniciando Asyncreq");
- JSONObject alumnos = ScrapDB(patente[0]);
- Log.i("PruebasBla", "Tengo JSONObject");
- Log.i("PruebasBla", alumnos.toString());
- return alumnos;
- }
- private JSONObject ScrapDB(String pat){
- // TODO Auto-generated method stub
- StringBuilder stringBuilder = new StringBuilder();
- try {
- HttpGet httpget = new HttpGet("http://testmobile.xephiro.com/ws/rest.php/load/alumnos/"+pat);
- HttpClient client = new DefaultHttpClient();
- HttpResponse response;
- stringBuilder = new StringBuilder();
- Log.i("PruebasBla", "Antes de ejecutar post");
- response = client.execute(httpget);
- HttpEntity entity = response.getEntity();
- InputStream stream = entity.getContent();
- int b;
- while ((b = stream.read()) != -1) {
- stringBuilder.append((char) b);
- }
- } catch (ClientProtocolException e) {
- Log.i("AGREGAR", "Client protocol exception");
- } catch (IOException e) {
- Log.i("AGREGAR", "IOException");
- }
- Log.i("PruebasBla", "Antes de crear json");
- JSONObject jsonObject = new JSONObject();
- try {
- jsonObject = new JSONObject(stringBuilder.toString());
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return jsonObject;
- }
- @Override
- protected void onPreExecute(){
- setProgressBarIndeterminateVisibility(true);
- }
- @Override
- protected void onPostExecute(JSONObject result){
- //pb.setVisibility(View.GONE);
- Log.i("PruebasBla", "dentro de post execute");
- if (result == null)
- {
- Log.e("AGREGAR", "NO SE OBTUVIERON ALUMNOS");
- }
- else{
- List<String> listArray = new ArrayList<String>();
- //spinnerArray.add("item1");
- //spinnerArray.add("item2");
- JSONArray pats;
- try {
- pats = result.getJSONArray("results");
- for (int i = 0, size = pats.length(); i < size; i++)
- {
- JSONObject furgoni = pats.getJSONObject(i);
- String patentei = furgoni.getString("Patente");
- listArray.add(patentei);
- }
- } catch (JSONException e) {
- // TODO Auto-generated catch block
- Log.i("PruebasBla", "catch");
- e.printStackTrace();
- }
- ArrayAdapter<String> adapter = new ArrayAdapter<String>(CheckIn.this, android.R.layout.simple_list_item_1, listArray);
- ListView lv = (ListView) findViewById(R.id.listView1);
- lv.setAdapter(adapter);
- setProgressBarIndeterminateVisibility(false);
- }
- }
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.check_in, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement