Java RecyclerView项目可单击但不可见

Java RecyclerView项目可单击但不可见,java,android,android-recyclerview,Java,Android,Android Recyclerview,我为这个问题挣扎了几天。 真奇怪。 我有一个具有以下结构的片段 ScrollView ConstraintLayout TextView1 TwoWayView1 TextView2 TwoWayView2 TwoWayView(RecyclerView库)正在填充项目, 我添加了一个McClickListener来测试项目是否确实存在。 所以当我点击物品所在区域的空白处时。它给了我该项目的正确位置和名称。但该项目不可见

我为这个问题挣扎了几天。 真奇怪。 我有一个具有以下结构的片段

ScrollView
    ConstraintLayout
        TextView1
        TwoWayView1
        TextView2
        TwoWayView2
TwoWayView(RecyclerView库)正在填充项目, 我添加了一个McClickListener来测试项目是否确实存在。 所以当我点击物品所在区域的空白处时。它给了我该项目的正确位置和名称。但该项目不可见

我真的希望有人能帮助我。 这是我的密码

片段事件

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:context="EventsFragment">

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/tvHeaderSocialEvents"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="32dp"
        android:text="Social Events"
        android:textSize="24sp"
        android:textStyle="bold"
        app:layout_constraintHorizontal_bias="0.033"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintTop_creator="1" />

    <org.lucasr.twowayview.widget.TwoWayView
        android:id="@+id/lvSocialEvents"
        style="@style/TwoWayView"
        android:layout_width="0dp"
        android:layout_height="260dp"
        android:layout_marginTop="8dp"
        android:clipChildren="true"
        android:clipToPadding="false"
        android:drawSelectorOnTop="false"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tvHeaderSocialEvents"
        tools:context=".activities.MenuGuillotineActivity"
        tools:layout_conversion_absoluteHeight="80dp"
        tools:layout_conversion_absoluteWidth="395dp"
        tools:layout_conversion_absoluteX="8dp"
        tools:layout_conversion_absoluteY="68dp" />


    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="846dp"
        android:text="temp"
        app:layout_constraintTop_toTopOf="parent"
        tools:layout_editor_absoluteX="175dp" />

    <TextView
        android:id="@+id/tvHeaderSportEvents"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="32dp"
        android:text="Sport Events"
        android:textSize="24sp"
        app:layout_constraintHorizontal_bias="0.027"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/lvSocialEvents" />

    <org.lucasr.twowayview.widget.TwoWayView
        android:id="@+id/lvSportEvents"
        style="@style/TwoWayView"
        android:layout_width="0dp"
        android:layout_height="80dp"
        android:layout_marginTop="8dp"
        android:drawSelectorOnTop="false"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tvHeaderSportEvents"
        tools:LayoutManager="TwoWayLayoutManager"
        tools:context=".activities.MenuGuillotineActivity"
        tools:layout_conversion_absoluteHeight="80dp"
        tools:layout_conversion_absoluteWidth="395dp"
        tools:layout_conversion_absoluteX="8dp"
        tools:layout_conversion_absoluteY="68dp" />

    <TextView
        android:id="@+id/tvHeaderOfficialEvents"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="32dp"
        android:text="Official Events"
        android:textSize="24sp"
        app:layout_constraintHorizontal_bias="0.025"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/lvSportEvents" />

    <org.lucasr.twowayview.widget.TwoWayView
        android:id="@+id/lvOfficialEvents"
        style="@style/TwoWayView"
        android:layout_width="0dp"
        android:layout_height="80dp"
        android:layout_marginTop="8dp"
        android:drawSelectorOnTop="false"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tvHeaderOfficialEvents"
        tools:LayoutManager="TwoWayLayoutManager"
        tools:context=".activities.MenuGuillotineActivity"
        tools:layout_conversion_absoluteHeight="80dp"
        tools:layout_conversion_absoluteWidth="395dp"
        tools:layout_conversion_absoluteX="8dp"
        tools:layout_conversion_absoluteY="68dp" />
    </android.support.constraint.ConstraintLayout>
</ScrollView>

事件片段

public class EventsFragment extends Fragment {

ArrayList<EventClass> eventClassArrayList;
RecyclerView.Adapter eventClassEventsAdapter;
TwoWayView lvSocialEvents;
View masterView;
TwoWayView lvSportEvents;
TwoWayView lvOfficialEvents;
StudentClass studentClass;
String studRank;
Context context;



public EventsFragment() {
    // Required empty public constructor
}

private void createHeadings(View view) {
    TextView lvHeaderSocialEvents = (TextView) view.findViewById(R.id.tvHeaderSocialEvents);
    lvHeaderSocialEvents.setTypeface(EasyFonts.caviarDreamsBold(context));
    TextView lvHeaderSportEvents = (TextView) view.findViewById(R.id.tvHeaderSportEvents);
    lvHeaderSportEvents.setTypeface(EasyFonts.caviarDreamsBold(context));
    TextView lvHeaderOfficialEvents = (TextView) view.findViewById(R.id.tvHeaderOfficialEvents);
    lvHeaderOfficialEvents.setTypeface(EasyFonts.caviarDreamsBold(context));

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_events, container, false);
    masterView = view;


    // Get Application Context
    context = getContext().getApplicationContext();
    Fresco.initialize(context);


    // Assign components
    lvSocialEvents = (TwoWayView) view.findViewById(R.id.lvSocialEvents);
    lvSocialEvents.setLayoutManager(new ListLayoutManager(context, TwoWayLayoutManager.Orientation.HORIZONTAL));


    lvSocialEvents.setHasFixedSize(true);
    lvSportEvents = (TwoWayView) view.findViewById(R.id.lvSportEvents);
    lvSportEvents.setLayoutManager(new ListLayoutManager(context, TwoWayLayoutManager.Orientation.HORIZONTAL));
    lvSportEvents.setHasFixedSize(true);
    lvOfficialEvents = (TwoWayView) view.findViewById(R.id.lvOfficialEvents);
    lvOfficialEvents.setLayoutManager(new ListLayoutManager(context, TwoWayLayoutManager.Orientation.HORIZONTAL));
    lvOfficialEvents.setHasFixedSize(true);

    createHeadings(view);

    // Get global data
    SharedPreferences global =  context.getSharedPreferences("globalData", MODE_PRIVATE);
    if (global.contains("student")) {
        //Get json from SP and decode json to EmployeeClass.
        SharedPreferences shared =  context.getSharedPreferences("studentData", MODE_PRIVATE);
        Gson gson = new Gson();
        String json = shared.getString("studentObject", "");
        studentClass = gson.fromJson(json, StudentClass.class);
        studRank = studentClass.rank;


    } else {
        studRank = "0";
    }


    // Get all the events from the Web server
    StringRequest stringRequest = new StringRequest(Request.Method.POST, getResources().getString(R.string.url_event), new Response.Listener<String>() {
        @Override
        public void onResponse(String output) {
            if (!output.isEmpty()) {
                ArrayList<CommunicationClass> data = new JsonConverter<CommunicationClass>().toArrayList(output, CommunicationClass.class);
                CommunicationClass comm = data.get(0);

                if (comm.code.equals("0")) {

                    // Create list for Events
                    eventClassArrayList = new JsonConverter<EventClass>().toArrayList(comm.info, EventClass.class);


                    // Create and add events to EventsAdapter and add to TwoWayView
                    eventClassEventsAdapter = new EventsAdapter(context,eventClassArrayList);

                    lvSocialEvents.setAdapter(eventClassEventsAdapter);
                    lvSportEvents.setAdapter(eventClassEventsAdapter);
                    lvOfficialEvents.setAdapter(eventClassEventsAdapter);

                    eventClassEventsAdapter.notifyDataSetChanged();

                } else {
                    ErrorHandling.makeText(context,comm.code, false).show();
                }
            } else {

            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError volleyError) {
            ErrorHandling.makeText(context, volleyError).showVolley();
        }
    }) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {

            //POST data for PHP Script
            HashMap<String, String> postDataEvents = new HashMap<String, String>();
            postDataEvents.put("event", "true");
            if (studRank.equals("0")) {
                postDataEvents.put("token", "public");
            } else {
                postDataEvents.put("token", studentClass.token);
            }
            return postDataEvents;
        }
    };

    MySingleton.getInstance(context).addToRequestQueue(stringRequest);

    com.example.howldevelopment.bcofficial.interfaces.ItemClickSupport itemClickSupport = com.example.howldevelopment.bcofficial.interfaces.ItemClickSupport.addTo(lvSocialEvents);
    itemClickSupport.setOnItemClickListener(new com.example.howldevelopment.bcofficial.interfaces.ItemClickSupport.OnItemClickListener() {
        @Override
        public void onItemClicked(RecyclerView recyclerView, int position, View v) {
            Toast.makeText(context, eventClassArrayList.get(position).name, Toast.LENGTH_SHORT).show();
        }
    });

    return view;
}

}
公共类事件片段扩展片段{
ArrayList eventClassArrayList;
适配器eventClassEventsAdapter;
双向视图LVSocialeEvents;
主视图;
双向观看体育赛事;
双向视图LV官方事件;
学生班学生班;
字符串studRank;
语境;
公共事件片段(){
//必需的空公共构造函数
}
私有void createheaders(视图){
TextView lvHeaderSocialEvents=(TextView)view.findViewById(R.id.tvHeaderSocialEvents);
lvHeaderSocialEvents.setTypeface(EasyFonts.caviarDreamsBold(上下文));
TextView lvHeaderSportEvents=(TextView)view.findViewById(R.id.tvHeaderSportEvents);
设置字体(EasyFonts.caviarDreamsBold(上下文));
TextView lvHeaderOfficialEvents=(TextView)view.findViewById(R.id.tvHeaderOfficialEvents);
lvHeaderOfficialEvents.setTypeface(EasyFonts.caviarDreamsBold(上下文));
}
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
//为该碎片膨胀布局
视图=充气机。充气(R.layout.fragment\u事件,容器,false);
主视图=视图;
//获取应用程序上下文
context=getContext().getApplicationContext();
壁画初始化(上下文);
//分配组件
lvSocialEvents=(双向视图)view.findViewById(R.id.lvSocialEvents);
setLayoutManager(新的ListLayoutManager(上下文,TwoWayLayoutManager.Orientation.HORIZONTAL));
lvSocialEvents.setHasFixedSize(true);
lvSportEvents=(双向视图)view.findViewById(R.id.lvSportEvents);
lvSportEvents.setLayoutManager(新的ListLayoutManager(context,TwoWayLayoutManager.Orientation.HORIZONTAL));
lvSportEvents.setHasFixedSize(true);
lvOfficialEvents=(双向视图)view.findViewById(R.id.lvOfficialEvents);
setLayoutManager(新的ListLayoutManager(上下文,TwoWayLayoutManager.Orientation.HORIZONTAL));
lvOfficialEvents.setHasFixedSize(true);
创建标题(视图);
//获取全局数据
SharedReferences global=context.getSharedReferences(“globalData”,MODE\u PRIVATE);
if(全局包含(“学生”)){
//从SP获取json并将json解码到EmployeeClass。
SharedReferences shared=context.getSharedReferences(“studentData”,MODE\u PRIVATE);
Gson Gson=新的Gson();
String json=shared.getString(“studentObject”和“”);
studentClass=gson.fromJson(json,studentClass.class);
studRank=studentClass.rank;
}否则{
studRank=“0”;
}
//从Web服务器获取所有事件
StringRequest StringRequest=newStringRequest(Request.Method.POST,getResources().getString(R.string.url\u事件),new Response.Listener(){
@凌驾
公共void onResponse(字符串输出){
如果(!output.isEmpty()){
ArrayList data=new JsonConverter().toArrayList(输出,CommunicationClass.class);
通信类comm=data.get(0);
如果(通信代码等于(“0”)){
//创建事件列表
eventClassArrayList=新建JsonConverter().toArrayList(comm.info,EventClass.class);
//创建事件并将其添加到EventsAdapter,然后添加到TwoWayView
eventClassEventsAdapter=新的EventsAdapter(上下文,eventClassArrayList);
lvSocialEvents.setAdapter(eventClassEventsAdapter);
设置适配器(eventClassEventsAdapter);
lvOfficialEvents.setAdapter(eventClassEventsAdapter);
eventClassEventsAdapter.notifyDataSetChanged();
}否则{
ErrorHandling.makeText(上下文,comm.code,false).show();
}
}否则{
}
}
},new Response.ErrorListener(){
@凌驾
公共错误响应(截击错误截击错误){
ErrorHandling.makeText(上下文,截击错误).showVolley();
}
}) {
@凌驾
受保护的映射getParams()引发AuthFailureError{
//PHP脚本的POST数据
HashMap postDataEvents=新HashMap();
postDataEvents.put(“事件”、“真”);
if(studRank.equals(“0”)){
postDataEvents.put(“令牌”、“公共”);
}否则{
postDataEvents.put(“token”,studentClass.token);
}
返回postDataEvents;
}
};
getInstance(上下文).addToRequestQueue(stringRequest);
com.example.howldevelopment.bcofficial.interfaces.ItemClickSupport ItemClickSupport=com.example.howldevelopment.bcofficial.interfaces.ItemClickSupport.addTo(LVSocialeEvents);
itemClickSupport.setOnItemClickListener(新的com.example.howldevelopment.bcofficial.interfaces.itemClickSupport.OnItemClickListener(){
@凌驾
单击公共空视图(RecyclerView RecyclerView,内部位置,视图v){
Toast.makeText(上下文,eventClassArrayList.get(position).name,Toast.LENGTH_SHORT.show();
}
});
返回视图;
}
}
EventsAdapter

public class EventsAdapter extends    RecyclerView.Adapter<EventsAdapter.EventViewHolder> {

private Context context;
private ArrayList<EventClass> events;
private LayoutInflater mInflater;

public EventsAdapter(Context context,ArrayList<EventClass> events) {
    mInflater = LayoutInflater.from(context);
    this.context = context;
    this.events = events;
}

@Override
public EventViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = mInflater.inflate(R.layout.event_item_1, parent, false);
    EventViewHolder holder = new EventViewHolder(view);
    return holder;
}

@Override
public void onBindViewHolder(EventViewHolder holder, int position) {
    Toast.makeText(context, events.get(position).name, Toast.LENGTH_SHORT).show();
    holder.tvName.setText(events.get(position).name);
    holder.tvDate.setText(events.get(position).date);
    holder.tvCost.setText(events.get(position).cost);
    holder.tvInterested.setText(events.get(position).interested);
}

@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
}

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

class EventViewHolder extends RecyclerView.ViewHolder {
    TextView tvName;
    TextView tvDate;
    TextView tvCost;
    TextView tvInterested;
    ImageView imgPoster;

    public EventViewHolder(View itemView) {
        super(itemView);
        tvName = (TextView) itemView.findViewById(R.id.tvEventName);
        tvDate = (TextView) itemView.findViewById(R.id.tvEventDate);
        tvCost = (TextView) itemView.findViewById(R.id.tvEventPrice);
        tvInterested = (TextView) itemView.findViewById(R.id.tvEventInterested);
    }
}

}
公共类EventsAdapter扩展了RecyclerView.Adapter{
私人语境;
一等兵