1

I am using cardview in recyclerview to list the result of retrofit request, next I want to get details of cardview that was clicked and display the details of cardview (json) in another activity The below code is my first activity in which I'm fetching the json using retrofit 2. This code is working fine, giving the out put json.

public class featured_listing extends AppCompatActivity {
      private RecyclerView featured_item_view;
      List<featuredListingModel> featuredListingModel;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_featured_listing);

        featured_item_view = (RecyclerView) findViewById(R.id.ui_featured_listing);

        Window window = getWindow();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            window.setStatusBarColor(getColor(R.color.login_statusbar_color));
        }
        else {
            window.setStatusBarColor(getResources().getColor(R.color.login_statusbar_color));
        }

        StaggeredGridLayoutManager mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(1 , StaggeredGridLayoutManager.VERTICAL);
        featured_item_view.setLayoutManager(mStaggeredGridLayoutManager);
        getData();

    }

    public void getData(){
        final Call<List<featuredListingModel>> featured_listingCall = RetrofitClient.getInstance().getApi().getFeaturedListing();
        featured_listingCall.enqueue(new Callback<List<featuredListingModel>>() {
            @Override
            public void onResponse(Call<List<featuredListingModel>> call, Response<List<featuredListingModel>> response) {
                int statusCode = response.code();
                  featuredListingModel = response.body();
                  featured_listing_adapter featuredListingAdapter = new featured_listing_adapter(featuredListingModel , getApplicationContext());
                  featured_item_view.setAdapter(featuredListingAdapter);
            }

            @Override
            public void onFailure(Call<List<featuredListingModel>> call, Throwable t) {

            }
        });

    }
}

Here is the adapter which i am using to get the cardview data...

public class featured_listing_adapter extends RecyclerView.Adapter<featured_listing_adapter.featured_listing_ViewHolder> {
    private static final String TAG = "RecyclerViewAdapter";
    private Context context;
    List<featuredListingModel> featuredItems;

    public featured_listing_adapter (List<featuredListingModel> _featuredItems  , Context _context){
             featuredItems =  _featuredItems;
        context = _context;
    }

    @Override
    public featured_listing_ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View viewItem = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_featured_listing_result , parent , false);
        featured_listing_ViewHolder featuredListingViewHolder = new featured_listing_ViewHolder(viewItem);
        return featuredListingViewHolder;
    }

    @Override
    public void onBindViewHolder(featured_listing_ViewHolder holder, final int position) {

        holder.mDoc_name.setText(featuredItems.get(position).getName());
        holder.mDoc_email.setText(featuredItems.get(position).getEmail());
        holder.mDoc_phone.setText(featuredItems.get(position).getPhone());
        holder.mDoc_like.setText(featuredItems.get(position).getLikes());
        holder.mDoc_directory_type.setText(featuredItems.get(position).getDirectoryTypeName());
        Picasso.get().load(featuredItems.get(position).getImgUrl()).into(holder.mDoc_image);

        holder.featured_listing_card_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
             Intent intent = new Intent(v.getContext() , Search_Result.class);
             v.getContext().startActivity(intent);
            }
        });
   }

    @Override
    public int getItemCount() {
        return featuredItems.size();
    }


    public static class featured_listing_ViewHolder extends RecyclerView.ViewHolder{

        @BindView(R.id.featured_listing_cardview) CardView featured_listing_card_view;

        @BindView(R.id.doc_img)  ImageView mDoc_image;

        @BindView(R.id.home_doc_name) TextView mDoc_name;

        @BindView(R.id.home_doc_phone) TextView mDoc_phone;

        @BindView(R.id.home_doc_email) TextView mDoc_email;

        @BindView(R.id.ui_likes) TextView mDoc_like;

        @BindView(R.id.ui_directory_type) TextView mDoc_directory_type;


        public featured_listing_ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this , itemView);
        }
    }
}

and now i want to get detail of each cardview in an other activity..... and i cant understand how to do that ..... i have another retrofit request for this work....

@FormUrlEncoded
    @POST("doc/doc_detail")
    Call<List<DocDetail>> getDocDetail(@Query("id") int id);

and this is the model class to get the detail of each card from server using retrofit ....

public class DocDetail {

    @SerializedName("name")
    @Expose
    private String name;
    @SerializedName("id")
    @Expose
    private String id;
    @SerializedName("image")
    @Expose
    private String image;
    @SerializedName("banner")
    @Expose
    private String banner;
    @SerializedName("directory_type")
    @Expose
    private Object directoryType;
    @SerializedName("directory_type_name")
    @Expose
    private String directoryTypeName;
    @SerializedName("directory_type_url")
    @Expose
    private Boolean directoryTypeUrl;
    @SerializedName("video_url")
    @Expose
    private Object videoUrl;
    @SerializedName("address")
    @Expose
    private Object address;
    @SerializedName("fax")
    @Expose
    private Object fax;
    @SerializedName("website")
    @Expose
    private Object website;
    @SerializedName("language")
    @Expose
    private Object language;
    @SerializedName("verify")
    @Expose
    private Object verify;
    @SerializedName("user_featured")
    @Expose
    private String userFeatured;
    @SerializedName("latitude")
    @Expose
    private Object latitude;
    @SerializedName("longitude")
    @Expose
    private Object longitude;
    @SerializedName("location")
    @Expose
    private Object location;
    @SerializedName("views")
    @Expose
    private Object views;
    @SerializedName("facebook")
    @Expose
    private Object facebook;
    @SerializedName("twitter")
    @Expose
    private Object twitter;
    @SerializedName("linkedin")
    @Expose
    private Object linkedin;
    @SerializedName("pinterest")
    @Expose
    private Object pinterest;
    @SerializedName("google_plus")
    @Expose
    private Object googlePlus;
    @SerializedName("tumblr")
    @Expose
    private Object tumblr;
    @SerializedName("instagram")
    @Expose
    private Object instagram;
    @SerializedName("skype")
    @Expose
    private Object skype;
    @SerializedName("zip")
    @Expose
    private Object zip;
    @SerializedName("tagline")
    @Expose
    private Object tagline;
    @SerializedName("description")
    @Expose
    private Object description;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public String getBanner() {
        return banner;
    }

    public void setBanner(String banner) {
        this.banner = banner;
    }

    public Object getDirectoryType() {
        return directoryType;
    }

    public void setDirectoryType(Object directoryType) {
        this.directoryType = directoryType;
    }

    public String getDirectoryTypeName() {
        return directoryTypeName;
    }

    public void setDirectoryTypeName(String directoryTypeName) {
        this.directoryTypeName = directoryTypeName;
    }

    public Boolean getDirectoryTypeUrl() {
        return directoryTypeUrl;
    }

    public void setDirectoryTypeUrl(Boolean directoryTypeUrl) {
        this.directoryTypeUrl = directoryTypeUrl;
    }

    public Object getVideoUrl() {
        return videoUrl;
    }

    public void setVideoUrl(Object videoUrl) {
        this.videoUrl = videoUrl;
    }

    public Object getAddress() {
        return address;
    }

    public void setAddress(Object address) {
        this.address = address;
    }

    public Object getFax() {
        return fax;
    }

    public void setFax(Object fax) {
        this.fax = fax;
    }

    public Object getWebsite() {
        return website;
    }

    public void setWebsite(Object website) {
        this.website = website;
    }

    public Object getLanguage() {
        return language;
    }

    public void setLanguage(Object language) {
        this.language = language;
    }

    public Object getVerify() {
        return verify;
    }

    public void setVerify(Object verify) {
        this.verify = verify;
    }

    public String getUserFeatured() {
        return userFeatured;
    }

    public void setUserFeatured(String userFeatured) {
        this.userFeatured = userFeatured;
    }

    public Object getLatitude() {
        return latitude;
    }

    public void setLatitude(Object latitude) {
        this.latitude = latitude;
    }

    public Object getLongitude() {
        return longitude;
    }

    public void setLongitude(Object longitude) {
        this.longitude = longitude;
    }

    public Object getLocation() {
        return location;
    }

    public void setLocation(Object location) {
        this.location = location;
    }

    public Object getViews() {
        return views;
    }

    public void setViews(Object views) {
        this.views = views;
    }

    public Object getFacebook() {
        return facebook;
    }

    public void setFacebook(Object facebook) {
        this.facebook = facebook;
    }

    public Object getTwitter() {
        return twitter;
    }

    public void setTwitter(Object twitter) {
        this.twitter = twitter;
    }

    public Object getLinkedin() {
        return linkedin;
    }

    public void setLinkedin(Object linkedin) {
        this.linkedin = linkedin;
    }

    public Object getPinterest() {
        return pinterest;
    }

    public void setPinterest(Object pinterest) {
        this.pinterest = pinterest;
    }

    public Object getGooglePlus() {
        return googlePlus;
    }

    public void setGooglePlus(Object googlePlus) {
        this.googlePlus = googlePlus;
    }

    public Object getTumblr() {
        return tumblr;
    }

    public void setTumblr(Object tumblr) {
        this.tumblr = tumblr;
    }

    public Object getInstagram() {
        return instagram;
    }

    public void setInstagram(Object instagram) {
        this.instagram = instagram;
    }

    public Object getSkype() {
        return skype;
    }

    public void setSkype(Object skype) {
        this.skype = skype;
    }

    public Object getZip() {
        return zip;
    }

    public void setZip(Object zip) {
        this.zip = zip;
    }

    public Object getTagline() {
        return tagline;
    }

    public void setTagline(Object tagline) {
        this.tagline = tagline;
    }

    public Object getDescription() {
        return description;
    }

    public void setDescription(Object description) {
        this.description = description;
    }
}

please help ....

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.