我尝试从我的服务器获取一些数据并将其填充在我的gridView中,该gridView位于片段中,我使用volley JsonArrayRequest来从服务器获取数据。 我的问题是,当执行请求时,它会永远停留在ProgressDialog中 没有解雇,也没有回复。
url字符串和onCreate:
private static final String URL_INDEX = "http://myserveripadrss/product.php";
public void onViewCreated(View view, Bundle savedInstanceState) {
gridView = (GridView) view.findViewById(R.id.gridView);
images = new ArrayList<>();
productTitles = new ArrayList<>();
fetchServer();
}
private void fetchServer(){
//Showing a progress dialog while our app fetches the data from url
final ProgressDialog loading = ProgressDialog.show(getActivity(), "Please wait...","Fetching data...",false,false);
//Creating a json array request to get the json from our api
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest( URL_INDEX,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
//Dismissing the progressdialog on response
loading.dismiss();
//Displaying our grid
showGrid(response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}
);
php返回有效的json,但仍然像我说的响应列表器没有反应
任何建议都将不胜感激,谢谢!