简体   繁体   English

字符串数组数据未在TextView中显示

[英]String Array data not showing in TextView

I'm in the process of learning android app development however I have come to an impasse. 我正在学习Android应用程序开发,但是我陷入了僵局。 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. 我的RecyclerView正在拾取我的String数组中有多少项,但它没有在text1中显示实际数据,任何帮助都将非常感激。

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

<?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;
}

嗯......一切看起来都不错,你可以尝试设置它:

android:textColor="#000000"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM