Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* metodo que faz a requisição ao web service e retorna as estações percorridas
- com origem e destino selecionado */
- public void clicar(View src){
- // preenche a posicao das estacoes de entrada e saida
- entradaSelecionada = entradaEstacoes.getSelectedItemPosition();
- saidaSelecionada = saidaEstacoes.getSelectedItemPosition();
- //monsta objeto json a ser enviado na requisicao
- JSONObject joOrigemDestino = new JSONObject();
- try{
- joOrigemDestino.put("origem",estacoesObj.get(entradaSelecionada).getNomeEstacao());
- joOrigemDestino.put("destino",estacoesObj.get(saidaSelecionada).getNomeEstacao());
- Log.d("", "clicar: " + joOrigemDestino.toString());
- }catch(JSONException e){
- e.printStackTrace();
- }
- //objeto usado para preencher as estações retornadas
- final ArrayList<Estacao> estacoes = new ArrayList<Estacao>();
- //requisicao ao webservice
- RealizaRequisicao.getInstance().postJson(Simulador.this, urlSimulador(),joOrigemDestino,new VolleyCallbackObject() {
- @Override
- public void onSuccess(JSONObject result) {
- try{
- JSONArray array = result.getJSONArray("estacao");
- for(int i = 0; i < array.length(); i++){
- JSONObject jo = array.getJSONObject(i);
- try{
- estacoes.add(new Estacao(Integer.parseInt(jo.getString("codEstacao")),
- Integer.parseInt(jo.getString("linha")),
- jo.getString("nome")));
- }catch(JSONException ex){
- ex.printStackTrace();
- }
- }
- }catch (JSONException e){
- try{
- result = result.getJSONObject("estacao");
- estacoes.add(new Estacao(Integer.parseInt(result.getString("codEstacao")),
- Integer.parseInt(result.getString("linha")),
- result.getString("nome")));
- }catch(JSONException ex2){
- ex2.printStackTrace();
- }
- }
- //metodo que preenche o layout com as estações
- montarListaEstacoes(estacoes);
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment