Android 如何在安卓改型中显示WP注释
我想从服务器加载数据,为此我使用Android 如何在安卓改型中显示WP注释,android,json,Android,Json,我想从服务器加载数据,为此我使用改装。我希望加载帖子(标题、说明、图像等…)并使用数据加载此帖子的评论 我可以加载标题,说明,图像等。。。展示它的魅力。但我不知道如何在活动中显示帖子评论 ModelResponse(带getter和setter): public class R_CatModelResponse { @SerializedName("status") public String Cat_status; @SerializedName("count")
改装。我希望加载帖子(标题、说明、图像等…)并使用数据加载此帖子的评论
我可以加载标题,说明,图像等。。。展示它的魅力。但我不知道如何在活动中显示帖子评论
ModelResponse(带getter和setter):
public class R_CatModelResponse {
@SerializedName("status")
public String Cat_status;
@SerializedName("count")
public int Cat_count;
@SerializedName("pages")
public int Cat_pages;
@SerializedName("category")
public Retrofit_ColoniesModel category;
@SerializedName("posts")
public List<R_CatModel> Cat_posts;
public class R_CatModel {
@SerializedName("id")
public Integer id;
@SerializedName("type")
public String type;
@SerializedName("slug")
public String slug;
@SerializedName("url")
public String url;
@SerializedName("status")
public String status;
@SerializedName("title")
public String title;
@SerializedName("title_plain")
public String title_plain;
@SerializedName("content")
public String content;
@SerializedName("excerpt")
public String excerpt;
@SerializedName("date")
public String date;
@SerializedName("modified")
public String modified;
@SerializedName("comment_count")
public int comment_count;
@SerializedName("comment_status")
public String comment_status;
@SerializedName("thumbnail")
public String thumbnail;
@SerializedName("thumbnail_images")
public R_CatThumbnailImages thumbnail_images;
@SerializedName("categories")
public List<R_CatCategory> categories;
@SerializedName("author")
public R_CatAuthor catAuthor;
@SerializedName("comments")
public List<R_PostComment> comments;
public class CommentAdapter2 extends RecyclerView.Adapter<CommentAdapter2.ViewHolder> {
private List<R_PostComment> mDataSet;
private Context context;
public CommentAdapter2(Context context, List<R_PostComment> mDataSet) {
this.mDataSet = mDataSet;
this.context = context;
}
@Override
public CommentAdapter2.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.comment_layout, viewGroup, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(CommentAdapter2.ViewHolder viewHolder, int position) {
viewHolder.comment_name.setText( ??? );
viewHolder.comment_date.setText( ??? );
viewHolder.comment_content.setText(Html.fromHtml( ??? ));
}
@Override
public int getItemCount() {
return mDataSet.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
private TextView comment_name, comment_content, comment_date;
public ViewHolder(View view) {
super(view);
comment_name = (TextView) itemView.findViewById(R.id.comment_userName_text);
comment_content = (TextView) itemView.findViewById(R.id.comment_comment_text);
comment_date = (TextView) itemView.findViewById(R.id.comment_date_text);
}
}
}
@GET("?json=get_category_posts")
Call<R_CatModelResponse> getCatResponse(@Query("id") Integer id);
适配器代码(用于加载注释):
public class R_CatModelResponse {
@SerializedName("status")
public String Cat_status;
@SerializedName("count")
public int Cat_count;
@SerializedName("pages")
public int Cat_pages;
@SerializedName("category")
public Retrofit_ColoniesModel category;
@SerializedName("posts")
public List<R_CatModel> Cat_posts;
public class R_CatModel {
@SerializedName("id")
public Integer id;
@SerializedName("type")
public String type;
@SerializedName("slug")
public String slug;
@SerializedName("url")
public String url;
@SerializedName("status")
public String status;
@SerializedName("title")
public String title;
@SerializedName("title_plain")
public String title_plain;
@SerializedName("content")
public String content;
@SerializedName("excerpt")
public String excerpt;
@SerializedName("date")
public String date;
@SerializedName("modified")
public String modified;
@SerializedName("comment_count")
public int comment_count;
@SerializedName("comment_status")
public String comment_status;
@SerializedName("thumbnail")
public String thumbnail;
@SerializedName("thumbnail_images")
public R_CatThumbnailImages thumbnail_images;
@SerializedName("categories")
public List<R_CatCategory> categories;
@SerializedName("author")
public R_CatAuthor catAuthor;
@SerializedName("comments")
public List<R_PostComment> comments;
public class CommentAdapter2 extends RecyclerView.Adapter<CommentAdapter2.ViewHolder> {
private List<R_PostComment> mDataSet;
private Context context;
public CommentAdapter2(Context context, List<R_PostComment> mDataSet) {
this.mDataSet = mDataSet;
this.context = context;
}
@Override
public CommentAdapter2.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.comment_layout, viewGroup, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(CommentAdapter2.ViewHolder viewHolder, int position) {
viewHolder.comment_name.setText( ??? );
viewHolder.comment_date.setText( ??? );
viewHolder.comment_content.setText(Html.fromHtml( ??? ));
}
@Override
public int getItemCount() {
return mDataSet.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
private TextView comment_name, comment_content, comment_date;
public ViewHolder(View view) {
super(view);
comment_name = (TextView) itemView.findViewById(R.id.comment_userName_text);
comment_content = (TextView) itemView.findViewById(R.id.comment_comment_text);
comment_date = (TextView) itemView.findViewById(R.id.comment_date_text);
}
}
}
@GET("?json=get_category_posts")
Call<R_CatModelResponse> getCatResponse(@Query("id") Integer id);
公共类CommentAdapter2扩展了RecyclerView.Adapter{
私有列表数据集;
私人语境;
公共CommentAdapter2(上下文,列表mDataSet){
this.mDataSet=mDataSet;
this.context=上下文;
}
@凌驾
public CommentAdapter2.ViewHolder onCreateViewHolder(视图组视图组,int i){
View View=LayoutInflater.from(viewGroup.getContext()).flate(R.layout.comment\u layout,viewGroup,false);
返回新的ViewHolder(视图);
}
@凌驾
public void onBindViewHolder(CommentAdapter2.ViewHolder-ViewHolder,int位置){
viewHolder.comment_name.setText(??);
viewHolder.comment\u date.setText(??);
viewHolder.comment_content.setText(Html.fromHtml(?);
}
@凌驾
public int getItemCount(){
返回mDataSet.size();
}
公共类ViewHolder扩展了RecyclerView.ViewHolder{
私有文本查看评论名称、评论内容、评论日期;
公共视图持有者(视图){
超级(视图);
comment\u name=(TextView)itemView.findViewById(R.id.comment\u userName\u text);
comment\u content=(TextView)itemView.findViewById(R.id.comment\u comment\u text);
comment\u date=(TextView)itemView.findViewById(R.id.comment\u date\u text);
}
}
}
活动代码:
@SerializedName("id")
public int cmID;
@SerializedName("name")
public String cmName;
@SerializedName("url")
public String cmUrl;
@SerializedName("date")
public String cmDate;
@SerializedName("content")
public String cmContent;
@SerializedName("parent")
public int cmParent;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.post_show_page);
bindActivity();
// Initialize
favDB = new FavHelper(context);
//Give Data
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
postID = bundle.getInt("postID");
title = bundle.getString("title");
image = bundle.getString("image");
content = bundle.getString("content");
dateTime = bundle.getString("dateTime");
author = bundle.getString("author");
category = bundle.getString("category");
categoryID = bundle.getString("categoryID");
}
mAppBarLayout.addOnOffsetChangedListener(this);
// Setup comment RecyclerView
comment_Recyclerview.setLayoutManager(mLayoutManager);
comment_Recyclerview.setHasFixedSize(true);
startAlphaAnimation(mTitle, 0, View.INVISIBLE);
// Set Data into views
if (title != null) {
postShow_title.setText(title);
postShow_title2.setText(title);
title_sliding.setText(getResources().getString(R.string.comment_title) + " " + title);
}
loadPostProgressDialog.createAndShow(this);
if (image != null) {
Glide.with(this)
.load(image)
.placeholder(R.drawable.post_image)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target,
boolean isFromMemoryCache, boolean isFirstResource) {
loadPostProgressDialog.dissmis();
return false;
}
})
.into(post_cover);
}
if (content != null) {
post_content_web.getSettings().setJavaScriptEnabled(true);
WebSettings settings = post_content_web.getSettings();
settings.setDefaultTextEncodingName("utf-8");
post_content_web.loadData(content, "text/html; charset=utf-8", "utf-8");
}
if (dateTime != null) {
postShow_dateTime.setText(dateTime);
}
if (author != null) {
postShow_author.setText(author);
}
if (category != null) {
postShow_category.setText(category);
}
post_cover.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
BlurBehind.getInstance().execute(PostShow_page.this, new OnBlurCompleteListener() {
@Override
public void onBlurComplete() {
startActivity(new Intent(PostShow_page.this, DialogImage_page.class)
.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
.putExtra("imageCover", image));
}
});
}
});
postShow_category.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (categoryID != null) {
startActivity(new Intent(PostShow_page.this, Category_page.class)
.putExtra("categoryID", categoryID)
.putExtra("categoryTitle", category));
}
}
});
private void bindData() {
// Setup Connect
Retrofit_ApiInterface apiInterface = Retrofit_ApiClient.getClient().create(Retrofit_ApiInterface.class);
call.enqueue( ??? )
@Override
public void onFailure(Call<R_CatModelResponse> call, Throwable t) {
Toast.makeText(PostShow_page.this, "Failed", Toast.LENGTH_SHORT).show();
}
});
}
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.post\u show\u页面);
bindActivity();
//初始化
favDB=新的FavHelper(上下文);
//提供数据
Bundle Bundle=getIntent().getExtras();
if(bundle!=null){
postID=bundle.getInt(“postID”);
title=bundle.getString(“title”);
image=bundle.getString(“image”);
内容=bundle.getString(“内容”);
dateTime=bundle.getString(“dateTime”);
author=bundle.getString(“author”);
类别=bundle.getString(“类别”);
categoryID=bundle.getString(“categoryID”);
}
mAppBarLayout.addOnOffsetChangedListener(此);
//设置注释回收视图
注释_Recyclerview.setLayoutManager(mLayoutManager);
注释_Recyclerview.setHasFixedSize(true);
星际动画(mTitle,0,视图。不可见);
//将数据设置到视图中
如果(标题!=null){
postShow_title.setText(标题);
postShow_title2.setText(标题);
title_.setText(getResources().getString(R.string.comment_title)+“”+title);
}
loadPostProgressDialog.createAndShow(此);
如果(图像!=null){
用(这个)滑翔
.加载(图像)
.占位符(R.drawable.post_图像)
.listener(新的RequestListener(){
@凌驾
公共布尔onException(异常e、字符串模型、目标、布尔isFirstResource){
返回false;
}
@凌驾
公共布尔onResourceReady(可提取资源、字符串模型、目标、,
布尔值(从MemoryCache开始,布尔值为FirstResource){
loadPostProgressDialog.dissmis();
返回false;
}
})
.进入(邮政局封面);
}
如果(内容!=null){
post_content_web.getSettings().setJavaScriptEnabled(true);
WebSettings settings=post_content_web.getSettings();
setDefaultTextEncodingName(“utf-8”);
post_content_web.loadData(content,“text/html;charset=utf-8”,“utf-8”);
}
if(dateTime!=null){
postShow_dateTime.setText(dateTime);
}
if(author!=null){
postShow_author.setText(作者);
}
如果(类别!=null){
postShow_category.setText(类别);
}
post_cover.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
执行(PostShow_page.this,新的OnBlurCompleteListener(){
@凌驾
public void onfullcomplete(){
startActivity(新意图(PostShow_page.this、DialogImage_page.class)
.setFlags(意图.FLAG\u活动\u否\u动画)
.putExtra(“图像封面”,图像));
}
});
}
});
postShow_category.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
if(categoryID!=null){
startActivity(新意图(PostShow_page.this、Category_page.class)
.putExtra(“类别”,类别)
.putExtra(“分类”,类别));
}
}
});
私有void bindData(){
//设置连接
Reformation\u ApiInterface ApiInterface=Reformation\u ApiClient.getClient().create(Reformation\u ApiInterface.clas
private void bindData() {
// Setup Connect
Retrofit_ApiInterface apiInterface = Retrofit_ApiClient.getClient().create(Retrofit_ApiInterface.class);
Call<R_PostModelResponse> call = apiInterface.getPostResponse(postID);
final ProgressDialog progressDialog = new ProgressDialog(context);
progressDialog.show();
Log.d("PostID", "Post : " + postID);
call.enqueue(new Callback<R_PostModelResponse>() {
@Override
public void onResponse(Call<R_PostModelResponse> call, Response<R_PostModelResponse> response) {
if (response.body() != null) {
models.addAll(response.body().getPost().getComments());
Log.e("testComment", "" + response.body().getPost().getComment_count());
mAdaper.notifyDataSetChanged();
comment_Recyclerview.setAdapter(mAdaper);
progressDialog.dismiss();
} else {
progressDialog.dismiss();
}
}
@Override
public void onFailure(Call<R_PostModelResponse> call, Throwable t) {
Toast.makeText(PostShow_page.this, "Failed", Toast.LENGTH_SHORT).show();
progressDialog.dismiss();
}
});
}