Olá. Sou novo em desenvolvimento Android e estou com problema no código abaixo:
package br.com.tapanovisual.tvisual.fragments;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.zip.Inflater;
import br.com.tapanovisual.tvisual.Principal;
import br.com.tapanovisual.tvisual.R;
import br.com.tapanovisual.tvisual.ServiceHandler;
import br.com.tapanovisual.tvisual.adapters.ReservasAdapter;
import br.com.tapanovisual.tvisual.listviews.objetos.Reservas;
import static br.com.tapanovisual.tvisual.R.id.item_reserva;
import static br.com.tapanovisual.tvisual.R.id.listAux;
import static br.com.tapanovisual.tvisual.R.id.view;
import static java.lang.String.*;
// Created by thiago.c.melo on 17/01/2016.
public class FragmentFavoritos extends Fragment {
//Dialog private ProgressDialog pDialog; //URL GET RESERVAS private static String url = "http://tapanovisual.esy.es/selectUltimasReservas.php";
//JSON node Names private static final String TAG_NAME = "nome"; private static final String TAG_RESERVAS = "estabelecimentos";
//JSONArray - Reservas JSONArray JsonReservas = null; //Hashmap para lista ArrayList<HashMap<String, String>> reservaslist;
ListView lv;
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_favoritos, container, false);
reservaslist = new ArrayList<HashMap<String, String>>(); final ListView lv = (ListView) view.findViewById(R.id.listAux);
//Buscando Dados Bando de Dados new GetReservas().execute();
return view; }
class GetReservas extends AsyncTask<Void, Void, Void>{
@Override protected void onPreExecute() { super.onPreExecute(); pDialog = new ProgressDialog(getActivity()); pDialog.setMessage("Carregando ultimas reservas..."); pDialog.setIndeterminate(false); pDialog.setCancelable(false); pDialog.show(); }
@Override public Void doInBackground(Void...arg0) {
//Criando Serviço Handler class Instacia ServiceHandler sh = new ServiceHandler(); String jsonStr = sh.ServiceCall(url, ServiceHandler.GET);
Log.d("Response: ", "> " + jsonStr);
if(jsonStr != null){ try { JSONObject JsonObj = new JSONObject(jsonStr); // Getting JSON Array node JsonReservas = JsonObj.getJSONArray(TAG_RESERVAS);
//Looping all Reservas for (int i = 0; i < JsonReservas.length(); i++){
JSONObject c = JsonReservas.getJSONObject(i); String nome = c.getString(TAG_NAME);
//HashMap para single reserva HashMap<String, String> reserva = new HashMap<String, String>(); //Adicionando valor no HashMap reserva.put(TAG_NAME, nome);
//Adicionando reserva na lista de reservas reservaslist.add(reserva);
}
} catch (JSONException e) { e.printStackTrace(); } }else{ Log.e("ServiceHandler", "Não foi possivél encontrar dados na URL"); } return null; }
@Override protected void onPostExecute(Void result) { super.onPostExecute(result); if(pDialog.isShowing()){ pDialog.dismiss(); }
//Inserindo ParseJson na Lista ListAdapter adapter = new SimpleAdapter(getActivity(), reservaslist, R.layout.item_reserva, new String[]{TAG_NAME}); lv.setAdapter(adapter);
} }
}
Quando eu faço:
ListAdapter adapter = new SimpleAdapter(getActivity(), reservaslist, R.layout.item_reserva, new String[]{TAG_NAME});
Dá erro no getActivity() da sintaxe acima. Estou desenvolvendo dentro de um Fragment e já tentei de tudo (Context)
Erro apresentado
Error:(147, 35) error: constructor SimpleAdapter in class SimpleAdapter cannot be applied to given types;
required: Context,List<? extends Map>,int,String[],int[]
found: FragmentActivity,ArrayList<HashMap<String,String>>,int,String[]
reason: actual and formal argument lists differ in length
Alguém conseguiria me ajudar?
Obrigado.