2017-02-20 2 views
-1

문제 : PHP 페이지에서 DB로 쿼리를 만들려고 할 때 쿼리 결과가 스마트 폰에 "도착하지 않았습니다". 시스템이 확신을 쿼리가 도착할 때까지 헤딩슛은 잠금을 얻기도 난 경우 결과 변수와 동일 아무것도 bcause 잘 모르겠어요, 아무것도 표시되지 않을 것이다 재활용,이 실행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(); 
} 

PHP 페이지의 결과지만, 내가 잘못 생각, 어떤 아이디어 모르겠 ??? 대신 데이터베이스와 안드로이드 응용 프로그램간에 데이터 전송을위한 웹 서버를 작성

답변

0

사용을 실시간으로 데이터베이스

+0

당신은 로컬 데이터베이스를 사용해야한다는 것을 의미합니다. 그것으로 쿼리합니까? –

+0

당신은 구글에 의해 거의 무료 firebase (database as a service)를 사용할 수 있습니다. u는 웹 사이트 – angryBird

+0

에서 자습서를 찾을 수 있습니다.이 웹 서버는 사용하기가 쉽고 복잡하지 않습니다. – angryBird

0

당신이 JsonArrayRequest

PHP에서 데이터의 recyclerview 사용 jsonArray 유형에 대한 데이터의 무리를 얻고 사용하려는 경우
0

글쎄, 나는 해결책을 찾았습니다. 메소드에서 "onResponse"라는 메소드 안에있는 리사이클 러에있는 모든 데이터를 표시하는 메소드를 넣었습니다.이 방법으로 메소드가 잠금을 얻었고 응답이 널이 될 때까지 기다렸습니다. 그 후 리사이클 러에서 everithing을 표시합니다.