Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String Array data not showing in TextView

Tags:

java

android

I'm in the process of learning android app development however I have come to an impasse. My RecyclerView is picking up how many items are in my String array however it is not showing the 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 corresponding 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 fragment

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;
}
like image 378
Nick Fallows Avatar asked May 01 '26 14:05

Nick Fallows


1 Answers

Hm... everything looks ok, can you try setting this to it:

android:textColor="#000000"
like image 108
Bojan Kseneman Avatar answered May 04 '26 04:05

Bojan Kseneman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!