2017-02-20 55 views
-1

這是問題: 當我嘗試通過php頁面查詢數據庫,查詢的結果沒有「到達」智能手機。與活動和查詢問題與飛利浦的MySQL服務器

setPartenza(tBoxPartenza.getText().toString()); 
setArrivo(tBoxArrivo.getText().toString()); 

final String KEY_FERM1 = "ferm_1"; 
final String KEY_FERM2 = "ferm_2"; 
String url = "<url>"; 
String ferm_1, ferm_2, jsonresp; 
String result = null; 



StringRequest stringRequest = new StringRequest(Request.Method.POST, url, 
     new Response.Listener<String>() { 
      @Override 
      public void onResponse(String response) { 
        Toast.makeText(MainActivity.this, "Response: " + response, Toast.LENGTH_SHORT).show(); 
        } 
      }, 
      new Response.ErrorListener() { 
        @Override 
        public void onErrorResponse(VolleyError error) { 
         Toast.makeText(MainActivity.this, "That didn't work!", Toast.LENGTH_SHORT).show(); 
        } 
      }) { 
        @Override 
         protected Map<String, String> getParams() throws AuthFailureError { 
          Map<String, String> params = new HashMap<>(); 
          params.put(KEY_FERM1, getPartenza()); 
          params.put(KEY_FERM2, getArrivo()); 
          return params; 
         } 
        }; 
        // Add the request to the RequestQueue. 
        RequestQueue queue = Volley.newRequestQueue(this); 
        queue.add(stringRequest); 

if (result != null) { 
     RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false); 
     recyclerView = (RecyclerView) findViewById(R.id.mainRecyclerView); 
     recyclerView.setLayoutManager(layoutManager); 
     MainRecyclerAdapter adapter = null; 
     try { 
      adapter = new MainRecyclerAdapter(getApplicationContext(), result); 
     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 
     recyclerView.setAdapter(new AlphaInAnimationAdapter(adapter)); 
} else { 
     Toast.makeText(this, "result == null", Toast.LENGTH_SHORT).show(); 
} 

當系統執行此,在回收不會出現什麼,bcause結果變量等於什麼都沒有,好,我不知道是否凌空獲得鎖,直到查詢到達,我也敢肯定的PHP頁面的結果,但我不知道我錯在哪裏,有什麼想法?

回答

0

使用實時數據庫,而不是寫數據庫和Android應用之間的數據傳輸網絡服務器

+0

你的意思是我需要使用本地數據庫和用它查詢? –

+0

你可以使用firebase(數據庫作爲服務)幾乎免費的谷歌..你可以找到他們的教程在網站上 – angryBird

+0

它的快速簡單易用和不復雜,因爲這些網絡服務器 – angryBird

0

如果你正試圖從PHP得到一堆數據的recyclerview使用jsonArray類型的數據,並使用JsonArrayRequest

0

編程小時後,我找到了解決方案,我把方法顯示在方法「onResponse」內的回收站上的所有數據,通過這種方法得到鎖,直到響應不爲空,它等待...之後,它顯示在回收站everithing