Professional Documents
Culture Documents
Manual para Consumir Un Web Service
Manual para Consumir Un Web Service
2. Dentro de ésta clase pegar el siguiente código (Nos servirá para la lectura o recorrido del
JSON)
5.2. Instanciamos la UI
editxtCedula = (EditText) findViewById(R.id.editTextCedula);
Card=(CardView) findViewById(R.id.Card);
btnNueva=(Button) findViewById(R.id.New);
btnBuscar = (Button) findViewById(R.id.buttonObtenerDatos);
@Override
protected void onPreExecute() {
}
@Override
protected String[] doInBackground(String... url) {
try {
jsonObjectText = JSONParser.readJsonFromUrl(url[0]);
objetos[0]=jsonObjectText.getJSONArray("rows").getJSONObject(0).getJSONArray("cell").g
etString(1);
objetos[1]=jsonObjectText.getJSONArray("rows").getJSONObject(0).getJSONArray("cell").g
etString(0);
objetos[2]=jsonObjectText.getJSONArray("rows").getJSONObject(0).getJSONArray("cell").g
etString(3);
objetos[3]=jsonObjectText.getJSONArray("rows").getJSONObject(0).getJSONArray("cell").g
etString(6);
objetos[4]=jsonObjectText.getJSONArray("rows").getJSONObject(0).getJSONArray("cell").g
etString(7);
objetos[5]=jsonObjectText.getJSONArray("rows").getJSONObject(0).getJSONArray("cell").g
etString(13);
return objetos;
}
@Override
protected void onPostExecute(String[] stringFromDoInBackground) {
if (!stringFromDoInBackground[0].contains("ul")){
Card.setVisibility(View.VISIBLE);
editxtCedula.setVisibility(View.GONE);
btnBuscar.setVisibility(View.GONE);
textViewNames.setText(stringFromDoInBackground[0]);
textViewLastNames.setText(stringFromDoInBackground[1]);
textViewBirthday.setText("Fecha de Nacimiento:
"+stringFromDoInBackground[2]);
textViewMom.setText("Madre: "+stringFromDoInBackground[3]);
textViewDad.setText("Padre: "+stringFromDoInBackground[4]);
textViewOcupation.setText("Ocupación: "+stringFromDoInBackground[5]);
}else{
Card.setVisibility(View.INVISIBLE);
editxtCedula.setText("");
editxtCedula.setVisibility(View.VISIBLE);
btnBuscar.setVisibility(View.VISIBLE);
Toast.makeText(getApplicationContext(),"La cédula no
existe",Toast.LENGTH_LONG).show();
}
}
}