如果启用或禁用,请选中“赞”按钮

时间:2017-11-22 22:16:03

标签: android android-studio android-recyclerview

我有像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天前我试图找出它或任何想法,但没有任何成果我希望得到想法或一个好的解决方案,提前谢谢

1 个答案:

答案 0 :(得分:0)

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

netscape.javascript.
netscape.security
com.sun.java.browser.plugin2
sun.plugin.cache
sun.plugin.dom
sun.plugin.extension
sun.plugin.javascript
sun.plugin.liveconnect
sun.plugin.navig
sun.plugin.net
sun.plugin.perf
sun.plugin.security
sun.plugin.services
sun.plugin.util
sun.plugin.viewersun.plugin2.applet
sun.plugin2.gluegen
sun.plugin2.ipc
sun.plugin2.jvm
sun.plugin2.liveconnect
sun.plugin2.main
sun.plugin2.message
sun.plugin2.os
sun.plugin2.util
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;
        }
相关问题