Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to do Jsonrequest on main thread or to run adapter view after the request in Android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 14
    Answer it
    @Override
    public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
                             Bundle savedInstanceState) {
    
       Bundle args = getArguments();
       double lats = args.getDouble(LATS, Lats);
       double logs = args.getDouble(LOGS, Logs);
        final Bundle bundle = new Bundle();
        bundle.putDouble(RestaurantAdapter.LATS, lats);
        bundle.putDouble(RestaurantAdapter.LOGS, logs);
         StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("https://maps.googleapis.com/maps/api/place/textsearch/json?");
    RequestQueue requestQueue = Volley.newRequestQueue(RestaurantFragment.this.getContext().getApplicationContext());
    JsonObjectRequest objectRequest = new JsonObjectRequest(Request.Method.GET, stringBuilder.toString(),null,
            new Response.Listener<JSONObject>() {
                @Override
        public void onResponse(JSONObject response) {
           try {JSONArray jsonObject = response.getJSONArray("results");
                for (int i = 0; i <= response.length(); i++) {
                    JSONObject jsonObject1 = jsonObject.getJSONObject(i);
                    String name = jsonObject1.get("name").toString();
                    String place = jsonObject1.get("formatted_address").toString();
                    objforRest objforRest = new objforRest(name,place);
                    arrayList1.add(objforRest);
                }
    
               Toast toast = Toast.makeText(RestaurantFragment.this.getContext(),arrayList1.toString(),Toast.LENGTH_LONG);
               toast.show();
    
            } catch (JSONException e) {
                e.printStackTrace();
            }
    }
            },new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) { }
    });
    

    requestqueue.add(objectRequestj);

       RecyclerView videoRecycler = (RecyclerView) inflater.inflate(
                    R.layout.fragment_restaurant2, container, false);
            videoRecycler.setHasFixedSize(true);
            RestaurantAdapter adapter = new RestaurantAdapter(bundle, RestaurantFragment.this.getContext(),arrayList1);
            videoRecycler.setAdapter(adapter);
            LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
            videoRecycler.setLayoutManager(layoutManager);
            return videoRecycler;
    
    }

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: