0

i have this android volley code. i dont have any problem here.

private void sendRequest() {
    StringRequest stringRequest = new StringRequest(JSON_url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            Log.d("HomeFragment", response);
            showJSON(response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(getActivity(), error.getMessage(), Toast.LENGTH_LONG).show();
        }
    });

    RequestQueue requestQueue = Volley.newRequestQueue(getActivity());
    requestQueue.add(stringRequest);

}

private void showJSON(String json) {
    MySingleton listJson = new MySingleton(json);
    listJson.mySingleton();
    List<myHome> homeData = new ArrayList<>();
    homeData.add(new myHome(MySingleton.vid_title, MySingleton.vid_desc, MySingleton.vid_duration, MySingleton.vid_thumbnail, MySingleton.embed_url, MySingleton.ids) );
    mAdapter = new HomeAdapter(getContext(), homeData);
    mRecyclerView.setAdapter(mAdapter);

and here is my adapter.

private String[] vid_title;
private String[] vid_desc;
private String[] vid_duration;
private String[] vid_thumbnail;
private String[] vid_embedUrl;
private int[] type;

private LayoutInflater inflater = null;
private List<myHome> multipleRowModelList;
private Context context;


public HomeAdapter(Context context, String[] title, String[] desc, String[] duration, String[] thumbnail, String[] embedUrl, int[] type) {
    this.context = context;
    this.vid_title = title;
    this.vid_desc = desc;
    this.vid_duration = duration;
    this.vid_thumbnail = thumbnail;
    this.vid_embedUrl = embedUrl;
    this.type = type;
    inflater = LayoutInflater.from(context);
}

my problem is here.

@Override
public int getItemCount() {
    return (multipleRowModelList != null && multipleRowModelList.size() > 0 ) ? multipleRowModelList.size() : 0;
}

@Override
public int getItemViewType(int position) {

    myHome multipleRowModel = multipleRowModelList.get(position);

    if (multipleRowModel != null)
        return type[position];

    return super.getItemViewType(position);
}

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

holder.featured_title.setText(multipleRowModelList.get(position).getTitle());
holder.featured_user.setText(multipleRowModelList.get(position).getUser());

the error is says, cannot resolve method 'setText(java.lang.String[])'

my model has data that is like this. String[] and int[].

any way i can do this?

here is the handler

public FeaturedViewHolder(View itemView, int type) {
    super(itemView);
    if (type == AppConstant.TYPE_FEATURED) {
        featured_title = (TextView)itemView.findViewById(R.id.title);
        featured_user = (TextView)itemView.findViewById(R.id.recvid_auth);
        mRelativeLayout = (RelativeLayout)itemView.findViewById(R.id.relative_recycler);

    }

    else if(type == AppConstant.TYPE_OTHER) {
        featured_title = (TextView)itemView.findViewById(R.id.recvid_title);
        featured_user = (TextView)itemView.findViewById(R.id.description);
        mRelativeLayout = (RelativeLayout)itemView.findViewById(R.id.relative_recycler_other);

    }

}

here is the model

public class myHome  {

String[] vid_title;
String[] vid_desc;
String[] vid_duration;
String[] vid_thumbnail;
String[] vid_embedUrl;
int[] type;


public myHome(String[] title, String[] desc, String[] duration, String[] thumbnail, String[] embedUrl, int[] type) {
    this.vid_title = title;
    this.vid_desc = desc;
    this.vid_duration = duration;
    this.vid_thumbnail = thumbnail;
    this.vid_embedUrl = embedUrl;
    this.type = type;
}

public String[] getTitle() {
    return vid_title;
}

public String[] getUser() {
    return vid_desc;
}

public String[] getViews() {
    return vid_duration;
}

public String[] getUrl() {
    return vid_thumbnail;
}

public String[] getDuration() {
    return vid_embedUrl;
}

public int[] getType() {
    return type;
}

i have edited my question

kathleen55
  • 341
  • 2
  • 9
  • 29

2 Answers2

0

Replace:

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

holder.featured_title.setText(multipleRowModelList.get(position).getTitle());
holder.featured_user.setText(multipleRowModelList.get(position).getUser());
}

with :

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

holder.featured_title.setText(multipleRowModelList.get(position).getTitle().toString());
holder.featured_user.setText(multipleRowModelList.get(position).getUser().toString());
Vivek_Neel
  • 1,343
  • 1
  • 14
  • 25
  • how about here sir? myHome multipleRowModel = multipleRowModelList.get(position); if (multipleRowModel != null) return multipleRowModel.getType().toString(); return needs to be int – kathleen55 May 11 '16 at 05:18
-1

Your code should be

public class myHome {

String vid_title;
String vid_desc;
String vid_duration;
String vid_thumbnail;
String vid_embedUrl;
int type;

public String getVid_title() {
    return vid_title;
}

public void setVid_title(String vid_title) {
    this.vid_title = vid_title;
}

public String getVid_desc() {
    return vid_desc;
}

public void setVid_desc(String vid_desc) {
    this.vid_desc = vid_desc;
}

public String getVid_duration() {
    return vid_duration;
}

public void setVid_duration(String vid_duration) {
    this.vid_duration = vid_duration;
}

public String getVid_thumbnail() {
    return vid_thumbnail;
}

public void setVid_thumbnail(String vid_thumbnail) {
    this.vid_thumbnail = vid_thumbnail;
}

public String getVid_embedUrl() {
    return vid_embedUrl;
}

public void setVid_embedUrl(String vid_embedUrl) {
    this.vid_embedUrl = vid_embedUrl;
}

public int getType() {
    return type;
}

public void setType(int type) {
    this.type = type;
}



}
siddhesh
  • 563
  • 1
  • 9
  • 15