从RecyclerView中的多个项目读取(System.out.println)

时间:2019-04-14 18:51:12

标签: java android android-recyclerview

Please see the user interface first

我的应用程序从在线服务器获取数据,并使用该数据进入回收站视图。 假设我的每个回收站视图都包含2个TextViews和3个按钮。

这是我的recyclerview的示例

Alex-123-视图-接受-拒绝

Jarvis-423-查看-接受-拒绝

所以我的每个回收站视图都包含5个项目,

现在我的问题是:

我需要从特定的回收站视图中获取textView读取的内容之一,这意味着,如果单击jarvis的回收站视图,我将得到System.out或吐司电话号码423。

这是我尝试过的距离:

MyAdapterForRecycleView1.java

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.NetworkError;
import com.android.volley.NoConnectionError;
import com.android.volley.ParseError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.ServerError;
import com.android.volley.TimeoutError;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;

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

import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class MyAdapterForRecycleView1 extends RecyclerView.Adapter<MyAdapterForRecycleView1.MyAdapterForRecycleView1ViewHolder>
{
    List<ListItemForRecycleView1> listItems;
    OnItemClickListener mListener;
    Context context;
    String allUserPhoneGet="";

    //public TextView allUserName, allUserPhone;

    public MyAdapterForRecycleView1(List<ListItemForRecycleView1> listItems, Context context)
    {
        this.listItems = listItems;
        this.context = context;
    }


    public interface OnItemClickListener
    {
        void onItemClick(int position);
    }

    public void setOnItemClickListener(OnItemClickListener listener)
    {
        mListener = listener;
    }

    public class MyAdapterForRecycleView1ViewHolder extends RecyclerView.ViewHolder
    {

        public TextView allUserName, allUserPhone;
        public Button accept, profileView, reject;

        public MyAdapterForRecycleView1ViewHolder(View itemView, final OnItemClickListener listener)
        {
            super(itemView);

            allUserName = itemView.findViewById(R.id.all_users_Name);
            allUserPhone = itemView.findViewById(R.id.all_users_Phone);
            accept = itemView.findViewById(R.id.userReq_acceptButton);
            profileView = itemView.findViewById(R.id.userReq_viewButton);
            reject = itemView.findViewById(R.id.userReq_rejectButton);

        }
    }

    @Override
    public MyAdapterForRecycleView1ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
    {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.all_users_display_layout, parent, false);
        MyAdapterForRecycleView1ViewHolder evh = new MyAdapterForRecycleView1ViewHolder(v, mListener);
        return evh;
    }

    @Override
    public void onBindViewHolder(MyAdapterForRecycleView1ViewHolder holder, int position)
    {
        //MyAdapterForRecycleView1Item currentItem = mMyAdapterForRecycleView1List.get(position);

        ListItemForRecycleView1 listItem = listItems.get(position);

        holder.allUserName.setText(listItem.getName());
        holder.allUserPhone.setText(listItem.getPhone());

        allUserPhoneGet = holder.allUserPhone.getText().toString();

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

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

0 个答案:

没有答案