0

anzuhängen. Ich benutze Recycler View, um den Artikel anzuzeigen, aber ich habe zwei Anfrage-URL, um die Daten über Volley zu holen. Ich versuchte, aber nicht gut funktioniert, kann nicht erhalten zweite Daten von JSON URL via Volley abrufen.Ich kann die Daten von der zweiten Anfrage-URL nicht anzeigen, um die erste Anfrage URL in Volley

Modell:

public class CartItemoriginal { 
public String productimg; 
public String productname; 
public String aliasname; 
public int qty; 
public String price; 
public String delivery; 
public String shippincharge; 
public String sellername; 
public String productid; 
private int Quantity; 

public CartItemoriginal(String productimg, String productname, String aliasname, int qty, String price, String delivery, String shippincharge, String sellername, String productid) { 
    this.productimg = productimg; 
    this.productname = productname; 
    this.aliasname = aliasname; 
    this.qty = qty; 
    this.price = price; 
    this.delivery = delivery; 
    this.shippincharge = shippincharge; 
    this.sellername = sellername; 
    this.productid = productid; 
} 

public CartItemoriginal(String productimg, String productname, String aliasname, int qty, String price, String productid) { 
    this.productimg = productimg; 
    this.productname = productname; 
    this.aliasname = aliasname; 
    this.qty = qty; 
    this.price = price; 
    this.productid = productid; 

} 
public CartItemoriginal(String delivery, String shippincharge, String sellername) { 
    this.delivery = delivery; 
    this.shippincharge = shippincharge; 
    this.sellername = sellername; 
} 


public int increaseQuantity(int quantity) { 
    if (quantity < 1) 
     quantity = 1; 
    else 
     quantity++; 

    Quantity = quantity; 
    return Quantity; 
} 

public String getProductimg() { 
    return productimg; 
} 

public void setProductimg(String productimg) { 
    this.productimg = productimg; 
} 

public String getProductname() { 
    return productname; 
} 

public void setProductname(String productname) { 
    this.productname = productname; 
} 

public String getAliasname() { 
    return aliasname; 
} 

public void setAliasname(String aliasname) { 
    this.aliasname = aliasname; 
} 

public int getQty() { 
    return qty; 
} 

public void setQty(int qty) { 
    this.qty = qty; 
} 

public String getPrice() { 
    return price; 
} 

public void setPrice(String price) { 
    this.price = price; 
} 

public String getDelivery() { 
    return delivery; 
} 

public void setDelivery(String delivery) { 
    this.delivery = delivery; 
} 

public String getShippincharge() { 
    return shippincharge; 
} 

public void setShippincharge(String shippincharge) { 
    this.shippincharge = shippincharge; 
} 

public String getSellername() { 
    return sellername; 
} 

public void setSellername(String sellername) { 
    this.sellername = sellername; 
} 

public String getProductid() { 
    return productid; 
} 

public void setProductid(String productid) { 
    this.productid = productid; 
} 

}

Adapter:

public class CartlistAdapter extends RecyclerView.Adapter <CartlistAdapter.ViewHolder> { 

    private ArrayList <CartItemoriginal> cartlistadp; 
    DisplayImageOptions options; 
    private Context context; 
    public static final String MyPREFERENCES = "MyPrefs"; 
    SharedPreferences.Editor editor; 
    SharedPreferences shared; 
    String pos; 
    private static final int VIEW_TYPE_ONE = 1; 
    private static final int VIEW_TYPE_TWO = 2; 



    public CartlistAdapter(ArrayList <CartItemoriginal> cartlistadp, Context context) { 

     this.cartlistadp = cartlistadp; 
     this.context = context; 
     options = new DisplayImageOptions.Builder().cacheOnDisk(true).cacheInMemory(true).showImageOnLoading(R.drawable.b2) 
      .showImageForEmptyUri(R.drawable.b2).build(); 
     if (YelloPage.imageLoader.isInited()) { 
      YelloPage.imageLoader.destroy(); 
     } 
     YelloPage.imageLoader.init(ImageLoaderConfiguration.createDefault(context)); 


    } 
    public CartlistAdapter() { 

    } 


    public int getItemViewType(int position) { 

     if (cartlistadp.size() == 0) { 
      Toast.makeText(context, String.valueOf(cartlistadp), Toast.LENGTH_LONG).show(); 
      return VIEW_TYPE_TWO; 

     } 
     return VIEW_TYPE_ONE; 
    } 


    @Override 
    public CartlistAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int position) { 

     ViewHolder viewHolder = null; 
     switch (position) { 
      case VIEW_TYPE_TWO: 
       View view2 = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.activity_cart, viewGroup, false); 
       viewHolder = new ViewHolder(view2); 
       // return view holder for your placeholder 
       break; 
      case VIEW_TYPE_ONE: 
       View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.cartitemrow, viewGroup, false); 
       viewHolder = new ViewHolder(view); 
       // return view holder for your normal list item 
       break; 
     } 
     return viewHolder; 


    } 

    @Override 
    public void onBindViewHolder(CartlistAdapter.ViewHolder viewHolder, int position) { 


     viewHolder.productnames.setText(cartlistadp.get(position).getProductname()); 
     viewHolder.cartalisname.setText(cartlistadp.get(position).getAliasname()); 
     viewHolder.cartprice.setText(cartlistadp.get(position).getPrice()); 
     viewHolder.cartdelivery.setText(cartlistadp.get(position).getDelivery()); 
     viewHolder.cartshippin.setText(cartlistadp.get(position).getShippincharge() + "%" + " " + "OFF"); 
     viewHolder.cartsellername.setText(cartlistadp.get(position).getSellername()); 
     // viewHolder.qty.setText(cartlistadp.get(position).getQty()); 
     // viewHolder.wishrating.setText(WishListadp.get(i).getCartitemname()); 

     YelloPage.imageLoader.displayImage(cartlistadp.get(position).getProductimg(), viewHolder.cartitemimg, options); 



    } 

    @Override 
    public int getItemCount() { 
     return cartlistadp.size(); 
    } 
    public long getItemId(int position) { 
     return position; 
    } 


    public class ViewHolder extends RecyclerView.ViewHolder { 
     private TextView productnames, cartalisname, cartprice, cartdelivery, cartshippin, cartsellername; 
     private ImageView cartitemimg; 
     private ImageButton wishbtn, removebtn; 
     private CardView cd; 
     private EditText qty; 

     public ViewHolder(final View view) { 
      super(view); 

      productnames = (TextView) view.findViewById(R.id.cartitemname); 
      cartalisname = (TextView) view.findViewById(R.id.cartalias); 
      cartprice = (TextView) view.findViewById(R.id.CartAmt); 
      cartdelivery = (TextView) view.findViewById(R.id.cartdel); 
      cartshippin = (TextView) view.findViewById(R.id.shippingcrg); 
      cartsellername = (TextView) view.findViewById(R.id.cartSellerName); 
      cartitemimg = (ImageView) view.findViewById(R.id.cartimg); 
      qty = (EditText) view.findViewById(R.id.quantity); 


      cd = (CardView) view.findViewById(R.id.cv); 
      productnames.setSingleLine(false); 
      productnames.setEllipsize(TextUtils.TruncateAt.END); 
      productnames.setMaxLines(2); 

     } 



    } 



} 

Code:

public void firstServiceCall(String list) { 
     url = Constants.singleproducturl + list; 
     showpDialog(); 
     JsonObjectRequest jsonObjReq = new JsonObjectRequest(
      Request.Method.GET, url, null, 
      new Response.Listener <JSONObject>() { 
       @Override 
       public void onResponse(JSONObject response) { 
        if (response != null) { 
         // int status=jsonObject.optInt("status"); 
         String status = response.optString("status"); 
         if (status.equalsIgnoreCase("200")) { //check the status 200 or not 
          try { 
           productpath = response.getString("productPath"); 
          } catch (JSONException e) { 
           e.printStackTrace(); 
          } 
          try { 
           JSONObject responses = response.getJSONObject("response"); 
           jsonarray = responses.getJSONArray(DATA); 

           if (jsonarray.length() > 0) { 
            // looping through json and adding to movies list 
            for (int i = 0; i < jsonarray.length(); i++) { 
             JSONObject product = jsonarray.getJSONObject(i); 
             cartpid = product.getString("product_id"); 
             cartproductname = product.getString("product_name"); 
             cartaliasname = product.getString("product_alias"); 
             cartprice = product.getString("mrp_price"); 
             sellerid = product.getString("seller_id"); 
             JSONArray pimg = product.getJSONArray("product_images"); 
             JSONObject firstimg = pimg.getJSONObject(0); 
             cartimg = firstimg.getString("original_res"); 
             String[] img2 = cartimg.split("\\."); 
             String imagone = productpath + sellerid + '/' + img2[0] + '(' + '2' + '0' + '0' + ')' + '.' + img2[1]; 
             int items = 2; 
             cart.add(new CartItemoriginal(imagone, cartproductname, cartaliasname, items, cartprice, cartpid)); 

            } 

           } 
          } catch (JSONException e) { 
           e.printStackTrace(); 
          } 
         pincodecheck(); 
          // cartadapter.notifyDataSetChanged(); 
          // stopping swipe refresh 
          // swipeRefreshLayout.setRefreshing(false); 
         } // condtion check the status 200 
         else // this is if status falied in runtime 
         { 
          Toast.makeText(CartItems.this, "Status Failed in Banner Page check ur network connection", Toast.LENGTH_LONG).show(); 
         } 

        } 
        hidepDialog(); 

       } 
      }, new Response.ErrorListener() { 

       @Override 
       public void onErrorResponse(VolleyError error) {} 
      }); 
     AppController.getInstance().addToRequestQueue(jsonObjReq); 
    } 

    /***************************************** second url volley ********************************************/ 
    public void pincodecheck() { 
     if (!pincode.isEmpty()) { 

      String pincon = pincode; 
      int pin4 = Integer.parseInt(pincon); 
      secondServiceCall(pin4, cartpid, sellerid); 

     } else { 
      Toast.makeText(getApplicationContext(), "error", Toast.LENGTH_LONG).show(); 
     } 
    } 
    public void secondServiceCall(int pin, String productid, String sellerid) { 

     String pinurl = "http://192.168.0.33/sharpswebsite3/qcrest1.0/?type=pinCodeCheck&result=json&product_id=" + productid + "&seller_id=" + sellerid + "&pinCode=" + pin; 
     // use this var membershipid acc to your need ... 
     JsonObjectRequest jsonObjReq = new JsonObjectRequest(
      Request.Method.GET, pinurl, null, 
      new Response.Listener <JSONObject>() { 
       @Override 
       public void onResponse(JSONObject response) { 

        if (response != null) { 
         // int status=jsonObject.optInt("status"); 
         String status = response.optString("status"); 
         if (status.equalsIgnoreCase("200")) { //check the status 200 or not 
          try { 
           JSONObject responses = response.getJSONObject("response"); 
           jsonarray = responses.getJSONArray(DATA); 
           if (jsonarray.length() > 0) { 
            // looping through json and adding to movies list 
            for (int i = 0; i < jsonarray.length(); i++) { 
             JSONObject product = jsonarray.getJSONObject(i); 
             process = product.getString("process"); 
             Message = product.getString("message"); 
             if (process.equalsIgnoreCase("success") && Message.equalsIgnoreCase("success")) { 
              cartdelivery = product.getString("delivery"); 
              cartshippingcharge = product.getString("shipping_charge"); 
              String pincode = product.getString("pincode"); 
              cart.add(new CartItemoriginal(cartdelivery, cartshippingcharge, "richard feloboune")); 

             } 




            } 
           } 
          } catch (JSONException e) { 
           e.printStackTrace(); 
          } 
          cartadapter.notifyDataSetChanged(); 
          // stopping swipe refresh 
          // swipeRefreshLayout.setRefreshing(false); 
         } // condtion check the status 200 
         else // this is if status falied in runtime 
         { 
          Toast.makeText(CartItems.this, "Status Failed in Banner Page check ur network connection", Toast.LENGTH_LONG).show(); 
         } 
        } 

        recyleitems = (RecyclerView) findViewById(R.id.mycartitem); 
        llm = new LinearLayoutManager(CartItems.this); 
        llm.setOrientation(LinearLayoutManager.VERTICAL); 
        recyleitems.setLayoutManager(llm); 
        recyleitems.setHasFixedSize(true); 
        cartadapter = new CartlistAdapter(cart, CartItems.this); 
        Log.i(String.valueOf(cartadapter), "cartadapter"); 
        recyleitems.setAdapter(cartadapter); 
        cartadapter.notifyDataSetChanged(); 

       } 
      }, new Response.ErrorListener() { 

       @Override 
       public void onErrorResponse(VolleyError error) {} 
      }); 
     AppController.getInstance().addToRequestQueue(jsonObjReq); 
    } 

kann ich erster urloutput nicht zweite bekommen zu bekommen.

So lösen Sie diesen Fehler, Vielen Dank im Voraus.

Antwort

0

Versuchen Sie, diese hinzuzufügen, nachdem zweiten Dienst nicht nach dem ersten Aufruf Aufruf

   recyleitems = (RecyclerView) findViewById(R.id.mycartitem); 
      llm = new LinearLayoutManager(CartItems.this); 
      llm.setOrientation(LinearLayoutManager.VERTICAL); 
      recyleitems.setLayoutManager(llm); 
      recyleitems.setHasFixedSize(true); 
      cartadapter = new CartlistAdapter(cart, CartItems.this); 
      Log.i(String.valueOf(cartadapter), "cartadapter"); 
      recyleitems.setAdapter(cartadapter); 
      cartadapter.notifyDataSetChanged(); 

und besserem Weg ist Ihre Ansicht nach in Ihrem onCreate erklären und nach dem Aufruf des Dienst nur Daten hinzufügen in benutzerdefinierten ArrayList und nach dem erfolgreichen Daten hinzugefügt in Ihrem List rufen Sie einfach youradapter.notifyDataSetChanged();

+0

I-Adapter auf dem zweiten Service genannt, aber einige Fehler bekam, dann müde oncreateview meines Adapter aber erster url Artikel namens – user2524

+0

Update Code nur dann angezeigt, und was war der Fehler ..? –

+0

ich aktualisiere meinen Code, lassen Sie überprüfen Sie oben – user2524