如果启用或禁用,请检查喜欢按钮

经过

我有像 facebook 这样的帖子,如果他启用或禁用,我如何检查我喜欢的按钮

我的json

{
  "posts": [
    {
      "id": "1",
      "userid": "1831",
      "authorname": "WhatsApp",
      "message": "There are only two times that I want to be with you: Now and Forever.",
      "likes": "0",
      "type": "romantic",
      "Likes": [
        {
          "userid": "814",
          "username": "jhon",
          "postid": "1"
        }
      ]
    },
    {
      "id": "2",
      "userid": "1831",
      "authorname": "WhatsApp",
      "message": "My six word love story: “I can’t imagine life without you.”",
      "likes": "0",
      "type": "romantic",
      "Likes": [

      ]
    },
    {
      "id": "3",
      "userid": "1831",
      "authorname": "WhatsApp",
      "message": "You have no idea how much my heart races when I see you.",
      "likes": "0",
      "type": "romantic",
      "Likes": [
        {
          "userid": "38919",
          "username": "Roman",
          "postid": "3"
        },
        {
          "userid": "291",
          "username": "haley",
          "postid": "3"
        }
      ]
    },
    {
      "id": "4",
      "userid": "1831",
      "authorname": "WhatsApp",
      "message": "Since the time I’ve met you, I cry a little less, laugh a little harder and smile all the more, just because I have you, my life is a better place.",
      "likes": "0",
      "type": "romantic",
      "Likes": [

      ]
    },

  ]
}

我可以在 Adapter_messages 上查看吗?

我的适配器

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.like.IconType;
import com.like.LikeButton;
import com.like.OnLikeListener;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;

import de.hdodenhof.circleimageview.CircleImageView;

public class Adapter_Messages extends RecyclerView.Adapter<Adapter_Messages.AdapterHolder>{
    ArrayList<Item_Messages> CategoriesList;
    Context context;
    Intent intent;
    Typeface typeface;




    public Adapter_Messages(Context context , ArrayList<Item_Messages> categories) {
        this.context = context;
        CategoriesList = categories;
    }

    @Override
    public AdapterHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_messages,parent,false);
        AdapterHolder adapterHolder = new AdapterHolder(v);
        typeface = Typeface.createFromAsset(context.getAssets(),"fonts/font-en.otf");
        return adapterHolder;
    }

    @Override
    public void onBindViewHolder(final AdapterHolder holder, final int position) {
        final Item_Messages item_messages = CategoriesList.get(position);
        Picasso.with(context).load("https://graph.facebook.com/" + item_messages.userid + "/picture?type=large").into(holder.profile_image_message);
        holder.txt_authorname.setText(item_messages.authorname);
        holder.txt_message.setText(item_messages.message);
        holder.txt_type.setText(item_messages.type);
        holder.txt_message.setTypeface(typeface);
        holder.txt_type.setTypeface(typeface);
        holder.txt_likes.setTypeface(typeface);
        holder.txt_authorname.setTypeface(typeface);
        holder.likeButton.setIcon(IconType.Thumb);
        holder.favoritebutton.setIcon(IconType.Heart);

        if(item_messages.likes.equals("0"))
        {
            holder.txt_likes.setText("there are no likes");
        }
        else{
            holder.txt_likes.setText(item_messages.likes + " Likes");
        }






        holder.img_facebook.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(context, "soon", Toast.LENGTH_SHORT).show();
            }
        });


        holder.img_whatsapp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(context, "soon", Toast.LENGTH_SHORT).show();
            }
        });


        holder.likeButton.setOnLikeListener(new OnLikeListener() {
            @Override
            public void liked(LikeButton likeButton) {
                if(Information.userid.equals(""))
                {
                    holder.likeButton.setLiked(false);
                    Toast.makeText(context, "First Login", Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void unLiked(LikeButton likeButton) {
                if(Information.userid.equals(""))
                {
                    Toast.makeText(context, "First Login", Toast.LENGTH_SHORT).show();
                }
            }
        });


        holder.favoritebutton.setOnLikeListener(new OnLikeListener() {
            @Override
            public void liked(LikeButton likeButton) {

            }

            @Override
            public void unLiked(LikeButton likeButton) {

            }
        });



    }

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

    class AdapterHolder extends RecyclerView.ViewHolder
    {



        CircleImageView profile_image_message;
        TextView txt_message,txt_type,txt_likes,txt_authorname;
        LikeButton likeButton,favoritebutton;
        ImageView img_copy,img_facebook,img_whatsapp;
        public AdapterHolder(View itemView) {
            super(itemView);
            profile_image_message = (CircleImageView)itemView.findViewById(R.id.profile_image_message);
            txt_authorname = (TextView)itemView.findViewById(R.id.txt_authorname);
            txt_message = (TextView)itemView.findViewById(R.id.txt_message);
            txt_type = (TextView)itemView.findViewById(R.id.txt_type);
            txt_likes = (TextView)itemView.findViewById(R.id.txt_likes);
            likeButton = (LikeButton)itemView.findViewById(R.id.likebutton);
            favoritebutton = (LikeButton)itemView.findViewById(R.id.favoritebutton);
            img_copy = (ImageView)itemView.findViewById(R.id.img_copy);
            img_facebook = (ImageView)itemView.findViewById(R.id.img_facebook);
            img_whatsapp = (ImageView)itemView.findViewById(R.id.img_whatsapp);
        }
    }


}

这是我的自定义数组列表

import java.util.ArrayList;

public class Item_Messages {


    String id,userid,authorname,message,likes,type;


    public Item_Messages(String id, String userid, String authorname, String message, String likes, String type) {
        this.id = id;
        this.userid = userid;
        this.authorname = authorname;
        this.message = message;
        this.likes = likes;
        this.type = type;
    }
}

和类 ShowMessages

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

import es.dmoral.toasty.Toasty;

public class ShowMessages extends AppCompatActivity {

    String type;
    ArrayList<Item_Messages> item_messages = new ArrayList<>();
    RecyclerView rv_message;




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_messages);




        Intent intent = getIntent();
        type = intent.getStringExtra("type");




        RequestQueue requestQueue = Volley.newRequestQueue(this);
        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, Information.URL_Messages + type, null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                try {


                    for (int x = 0; x < response.getJSONArray("posts").getJSONObject(x).length() ; x++) {
                        item_messages.add(new Item_Messages(response.getJSONArray("posts").getJSONObject(x).getString("id"),response.getJSONArray("posts").getJSONObject(x).getString("userid"),response.getJSONArray("posts").getJSONObject(x).getString("authorname"),response.getJSONArray("posts").getJSONObject(x).getString("message"),String.valueOf(response.getJSONArray("posts").getJSONObject(x).getJSONArray("Likes").length()),response.getJSONArray("posts").getJSONObject(x).getString("type")));
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                rv_message = (RecyclerView)findViewById(R.id.rv_message);
                rv_message.setLayoutManager(new LinearLayoutManager(ShowMessages.this,LinearLayoutManager.VERTICAL,false));
                Adapter_Messages adapterview = new Adapter_Messages(ShowMessages.this, item_messages);
                rv_message.setAdapter(adapterview);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        requestQueue.add(jsonObjectRequest);



    }
}

4 天前,我正在尝试以自己的方式检查它或任何想法,但没有任何结果我希望得到想法或好的解决方案,提前致谢

优素福·卡格拉

我不知道这是否最好,但我就是这样做的。

String idsLikedThis;    
    for(int i = 0; i < like.size(); i++)
         idsLikedThis = like.get(i)+",";
    idsLikedThis = idsLikedThis.substrings(0, idsLikedThis.length() - 1);

String id,userid,authorname,message,likes,idsLikedThis,type;

public Item_Messages(String id, String userid, String authorname, String message, String likes, String idsLikedThis, String type) {
            this.id = id;
            this.userid = userid;
            this.authorname = authorname;
            this.message = message;
            this.likes = likes;
            this.idsLikedThis = idsLikedThis
            this.type = type;
        }

ArrayList<String> idsLikedThis = Arrays.AsList(item_messages.idsLikedThis.split(","));
if(idsLikedThis.contains("users id"))
      button.enable

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如果记录不匹配,请禁用按钮

来自分类Dev

如何检查用户是否已“选中”复选框并启用提交按钮(如果选中,则禁用)?

来自分类Dev

检查.NET 3.5并启用(如果已禁用)

来自分类Dev

如果输入不为空,则启用禁用按钮

来自分类Dev

检查某些条件后禁用并启用按钮

来自分类Dev

如果文本字段已填写,请设置启用按钮

来自分类Dev

如果文本字段已填写,请设置启用按钮

来自分类Dev

如果验证中有任何错误,请禁用提交按钮

来自分类Dev

如果数量超出限制,请禁用单选按钮

来自分类Dev

如果未单击任何复选框,请禁用按钮

来自分类Dev

如果表单已打开,请禁用按钮和事件

来自分类Dev

如果验证中有任何错误,请禁用“提交”按钮

来自分类Dev

如果表值为1或更大,请禁用单选按钮

来自分类Dev

如果动态表没有行,则启用/禁用提交按钮

来自分类Dev

如何检查表单关闭按钮的状态(启用/禁用)

来自分类Dev

如何使用氦气检查启用和禁用按钮?

来自分类Dev

如何检查分页按钮是启用还是禁用

来自分类Dev

启用/禁用温泉按钮

来自分类Dev

Android:启用/禁用按钮

来自分类Dev

Javascript按钮启用或禁用

来自分类Dev

启用/禁用按钮

来自分类Dev

禁用/启用按钮-jQuery

来自分类Dev

Java启用/禁用按钮

来自分类Dev

启用和禁用按钮

来自分类Dev

Android:启用/禁用按钮

来自分类Dev

如果表单未填写,请禁用提交按钮并更改按钮的 CSS

来自分类Dev

如果地理位置不可用,请禁用按钮

来自分类Dev

PHP MySQL如果今天是星期天,请禁用按钮

来自分类Dev

禁用单选按钮检查