【发布时间】:2017-05-18 17:12:14
【问题描述】:
我正在做一个从 json 文件读取的 Asynctask 函数。我希望在 postExecute 上将其传递给我拥有的另一个 Activity,例如字符串联系人的“nombre, categoria, hora, lugar ...”。如何在 postExecute 上获取联系人的值?有人可以帮助我吗?这是我的代码
private class GetProgramaSC extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
pDialog = new ProgressDialog(getActivity());
if(idioma.equalsIgnoreCase("es")){
pDialog.setMessage("Por favor espere...");
}
else{
pDialog.setMessage("Itxaron mesedez...");
}
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected Void doInBackground(Void... arg0) {
try {
JSONObject jsonObj = new JSONObject(loadJSONFromAsset());
// Getting JSON Array node
eventos = jsonObj.getJSONArray("results");
// looping through All Contacts
for (int i = 0; i < eventos.length(); i++) {
JSONObject c = eventos.getJSONObject(i);
String categoria = c.getString(TAG_CATEGORIA);
String nombre = c.getString(TAG_NOMBRE);
String hora = c.getString(TAG_HORA);
String lugar = c.getString(TAG_LUGAR);
String fecha = c.getString(TAG_FECHA);
String coordenadas = c.getString(TAG_COORDENADAS);
String info = c.getString(TAG_INFO);
String imagen= c.getString(TAG_IMAGEN);
// tmp hashmap for single contact
HashMap<String, String> contact = new HashMap<String, String>();
// adding each child node to HashMap key => value
contact.put("categoria", categoria);
contact.put("nombre", nombre);
contact.put("hora", hora);
contact.put("nombre_lugar", lugar);
contact.put("fecha", fecha);
contact.put("coordenadas", coordenadas);
contact.put("info", info);
contact.put("imagen", imagen);
// adding contact to contact list
eventosList.add(contact);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// Dismiss the progress dialog
if (pDialog.isShowing())
pDialog.dismiss();
}
}
非常感谢
【问题讨论】: