String Array data not showing in TextView

I am developing Android apps, but I am stumped. My RecyclerView is collecting the number of items in my String array, however it doesn't display actual data in text1, any help would be much appreciated.

This is my adapter

public class EventCalenderAdapter extends RecyclerView.Adapter<EventCalenderAdapter.ViewHolder> {

static String[] fakeData = new String[] {
        "One","Two","Three","Four","Five","Ah..Ah..Ah"
};

static class ViewHolder extends RecyclerView.ViewHolder {
    CardView cardView;
    TextView titleView;

    public ViewHolder(CardView card) {
        super(card);
        cardView = card;
        titleView = (TextView) card.findViewById(R.id.text1);
    }
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int i) {
    CardView v = (CardView) LayoutInflater.from(parent.getContext()).inflate(R.layout.event_task, parent, false);
    return new ViewHolder(v);
}

@Override
public void onBindViewHolder(ViewHolder viewHolder, int i) {
    viewHolder.titleView.setText(fakeData[i]);
}

@Override
public int getItemCount() {
    return fakeData.length;
}

      

This is the relevant XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:event_view="http://schemas.android.com/apk/res-auto"
android:layout_height="100dp"
android:layout_width="match_parent"
android:id="@+id/event_view"
android:layout_marginTop="@dimen/task_card_half_spacing"
android:layout_marginBottom="@dimen/task_card_half_spacing"
android:layout_marginLeft="@dimen/gutter"
android:layout_marginRight="@dimen/gutter"
android:layout_gravity="center"
android:elevation="@dimen/task_card_elevation"
android:foreground="?android:attr/selectableItemBackground"
event_view:cardCornerRadius="0dp" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<ImageView
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:id="@+id/image"
    android:scaleType="centerCrop"
    android:layout_alignParentLeft="true"/>

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@android:style/TextAppearance.Medium.Inverse"
    android:id="@+id/text1"
    android:maxLines="1"
    android:ellipsize="end"
    android:padding="10dp"
    android:layout_alignTop="@+id/image"
    android:layout_toRightOf="@+id/image"/>

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    style="@android:style/TextAppearance.Inverse"
    android:id="@+id/text2"
    android:maxLines="3"
    android:ellipsize="end"
    android:padding="10dp"
    android:layout_alignStart="@+id/text1"
    android:layout_below="@+id/text1"/>


</RelativeLayout>

</android.support.v7.widget.CardView>

      

and this is my snippet

public class EventCalenderFragment extends Fragment {

RecyclerView recyclerView;
EventCalenderAdapter adapter;


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

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    adapter = new EventCalenderAdapter();
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    final View v = inflater.inflate(R.layout.fragment_event_calender, container, false);
    recyclerView = (RecyclerView) v.findViewById(R.id.recycler);
    recyclerView.setAdapter(adapter);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    return v;
}

      

+3


source to share


1 answer


Hm ... everything looks fine, can you try setting this for it:



android:textColor="#000000"

      

+2


source







All Articles