Ich habe ein paar Tage mit diesem Problem zu kämpfen. Es ist wirklich seltsam. Ich habe ein Fragment mit der folgenden Struktur.RecyclerView-Elemente sind anklickbar, aber unsichtbar
ScrollView
ConstraintLayout
TextView1
TwoWayView1
TextView2
TwoWayView2
Die TwoWayView (RecyclerView Bibliothek) mit den Elementen gefüllt wird, hinzugefügt ich einen onItemClickListener zu testen, ob die Gegenstände tatsächlich da ist. Also, wenn ich auf einen leeren Platz in dem Bereich klicke, wo der Gegenstand sein sollte. Es gibt mir die korrekte Position und den Namen dieses Artikels. Aber das Objekt ist nicht sichtbar.
Ich hoffe wirklich, dass mir jemand helfen kann. Hier ist mein Code.
fragment_events
<?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>
EventsFragment
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;
}
}
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);
}
}
}
d Es id Arbeit vor ein paar Stunden. Aber nachdem im EventAdapter weitere Komponenten und der benötigte Code hinzugefügt wurden. Es hat aufgehört zu arbeiten. Und versuchen Sie, zum Arbeitsaufbau zurückzukehren, aber kein Erfolg
Ich bekomme auch E/RecyclerView: Kein Adapter angeschlossen; Layoutfehler überspringen
weiße Textfarbe auf weißem Hintergrund? – 0X0nosugar
Ich dachte, du machst zuerst Witze. aber glaube mir. Ich habe es dir versprochen, ich habe es in dem geändert, der funktioniert hat. –
Und ich ging, um jetzt zu sehen. Ja, es war die graue Standardfarbe und aus irgendeinem Grund war es weiß? Es funktioniert jetzt. Ich kann es nicht glauben. Vielen Dank. –