我有这个android截击代码。我在这里没有任何问题。
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);
这是我的适配器。
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);
}
我的问题来了。
@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());
错误是说,无法解析方法"setText(java.lang.String[])"
我的模型有这样的数据。String[]和int[]。
我有办法做到这一点吗?
这是管理员
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);
}
}
这是型号
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;
}
我已经编辑了我的问题
替换:
@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());
}
带有:
@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());
您的代码应该是
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;
}
}