Apos horas de analise de codigo ainda nao consigo encontrar o erro simplesmente não aparece a minha lista com os horarios que são recebidos por json ! Tirei codigo que não achei necessario para o erro. O código esta a conseguir receber o json penso que o problema esteja aqui :
ListAdapter adapter = new SimpleAdapter(HorariosActivity.this, horariosList, R.layout.list_item,
new String[] {TAG_TITLE, TAG_DATESTART},
new int[] {R.id.title, R.id.dateStart});
listaHorarios.setAdapter(adapter);
A minha Activity:
public class HorariosActivity extends ActionBarActivity
implements GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
LocationListener {
private static final String TAG_TITLE = "Titulo";
private static final String TAG_DATESTART = "DataInicio";
private PagerAdapter mPagerAdapter;
private Context context;
ProgressDialog dialog;
private Toolbar mToolbar;
private Toolbar mToolbarBottom;
String horarios2;
ListView listaHorarios;
boolean estado;
String link ;
String varjson ="horarioHora";
ArrayList<String> horarios = new ArrayList<>();
ArrayList<String> linhas3 = new ArrayList<>();
ArrayList<HashMap<String,String>> horariosList;
private Drawer.Result navigationDrawerLeft;
private OnCheckedChangeListener mOnCheckedChangeListener = new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(IDrawerItem iDrawerItem, CompoundButton compoundButton, boolean b) {
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.horarios);
estado=true;
btnpesquisa = (Button) findViewById(R.id.btnpesquisa);
btnparagens = (Button) findViewById(R.id.btnparagens);
tvCoordinate = (TextView) findViewById(R.id.Localizacaotv);
link="http://dagobah.grifin.pt/tiagocoelho/horariosAndroid.php?linhaid=4¶gemid=36";
new Download().execute();
mToolbar = (Toolbar) findViewById(R.id.tb_main);
mToolbar.setTitle("Tumg");
mToolbar.setSubtitle("Marinha Grande");
listaHorarios = (ListView) findViewById(R.id.listEventos);
mToolbar.setLogo(R.drawable.ic_launcher);
setSupportActionBar(mToolbar);
GPSManager gps = new GPSManager(
HorariosActivity.this);
gps.start();
callConnection();
}
public class Download extends AsyncTask<Void, Void, String> {
protected String doInBackground(Void... params) {
String out = null;
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
String url_all_empresas = link;
final HttpParams httpParameters = httpClient.getParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 15000);
HttpConnectionParams.setSoTimeout(httpParameters, 15000);
HttpGet httpPost = new HttpGet(url_all_empresas);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
out = EntityUtils.toString(httpEntity, HTTP.UTF_8);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return out;
}
@Override
protected void onPreExecute()
{
super.onPreExecute();
estado = true;
dialog = ProgressDialog.show(HorariosActivity.this, "A autenticar", "A contactar o servidor, por favor, aguarde alguns instantes.", true, false);
}
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@Override
public void onPostExecute(final String result) {
super.onPostExecute(result);
try {
JSONArray jsonArray = new JSONArray(result);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsa = jsonArray.getJSONObject(i);
horarios2= jsa.getString(varjson);
dialog.dismiss();
String estado= jsa.getString("horarioEstado");
HashMap<String, String> evento = new HashMap<>();
evento.put("horarioHora", horarios2);
evento.put("horarioEstado", estado);
horariosList.add(evento);
}
ListAdapter adapter = new SimpleAdapter(HorariosActivity.this, horariosList, R.layout.list_item,
new String[] {TAG_TITLE, TAG_DATESTART},
new int[] {R.id.title, R.id.dateStart});
listaHorarios.setAdapter(adapter);
estado = false;
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
O meu horarios.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools">
<android.support.v7.widget.Toolbar
android:id="@+id/tb_main"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="#82d808" />
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/listEventos"
android:layout_alignParentTop="true"
android:layout_margin="15dp"
tools:listitem="@layout/list_item"/>
</RelativeLayout>
O meu list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dateStart"
android:id="@+id/dateStart"
android:layout_marginLeft="15dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="15dp"
android:textSize="15dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="title"
android:id="@+id/title"
android:layout_marginLeft="15dp"
android:layout_marginBottom="15dp"
android:textSize="20dp" />
</LinearLayout>