【问题标题】:Problems with android activity and query to MySQL server with Volleyandroid 活动问题和使用 Volley 查询 MySQL 服务器
【发布时间】:2017-02-20 15:42:32
【问题描述】:

这就是问题所在: 当我尝试通过 php 页面查询数据库时,查询结果没有“到达”智能手机。

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();
}

当系统执行此操作时,在回收器中不会出现任何内容,因为结果变量不等于任何内容,好吧,我不知道 volley 是否在查询到达之前获得锁,而且我确定结果php页面,但我不知道我错在哪里,有什么想法吗???

【问题讨论】:

    标签: php android mysql android-recyclerview android-volley


    【解决方案1】:

    如果您想为 recyclerview 获取一堆数据,请使用 jsonArray 类型的 php 数据并使用 JsonArrayRequest

    【讨论】:

      【解决方案2】:

      经过一个小时的编码,我找到了解决方案,我将在“onResponse”方法中显示所有数据的方法放在回收器上,通过这种方式,该方法获取锁,直到响应不为空,它等待.. . 之后它会在回收站上显示everithing

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-10-19
        • 1970-01-01
        • 1970-01-01
        • 2015-07-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多