Recycler视图问题

时间:2015-11-07 17:33:00

标签: android android-recyclerview

我正在尝试制作这样的日历: 它看起来像垃圾,因为它没有样式/适当的边距(我稍后会照顾它),不要介意这些东西 enter image description here

它在首次运行时效果很好,但是当我按下上一个或下一个按钮然后生成新视图时,它会提供输出,如第二个图像:enter image description here

不要介意上一个和下一个按钮之间的文本,这是硬编码用于测试目的(调整边距/填充) 标有蓝色笔的部分添加在上一个视图的正下方,我希望在按下按钮时清除以前的视图。这是我的活动:

/*
 * Copyright (c) $today.year.Copyright goes here.
 */

package neppro.com.busapp.Adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;
import java.util.zip.Inflater;

import neppro.com.busapp.R;
import neppro.com.busapp.interfaces.DataCarrierForAdapter;
import neppro.com.busapp.model.BusSearchResultWrapper;

/**
 * Created by RaazDk on 11/7/2015.
 */
public class DatePickerAdapter extends RecyclerView.Adapter<DatePickerAdapter.CalendarViewHolder>
implements DataCarrierForAdapter{
    private List<String> mMonthDays;
    private LayoutInflater layoutInflater;
    public DatePickerAdapter(Context context) {
        layoutInflater = LayoutInflater.from(context);

    }

    @Override
    public CalendarViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View CalendarSingleItem = layoutInflater
                .inflate(R.layout.calendar_single_date_layout, parent, false);
        CalendarViewHolder holder = new CalendarViewHolder(CalendarSingleItem);
        return  holder;
    }

    @Override
    public void onBindViewHolder(CalendarViewHolder holder, int position) {
        holder.CalendarSingleItem.setText(mMonthDays.get(position).toString());
    }

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

    @Override
    public void busSearchResultDataForAdapter(List<BusSearchResultWrapper.AvailableBus> busList,
                                              String fromLocation, String toLocation) {

    }

    @Override
    public void navMenuAdapterDataCarrier(Context context, RecyclerView recyclerView,
                                          Object adapterInstance, String[] menuText,
                                          String[] menuIcons) {

    }

    @Override
    public void CalendarDataCarrier(List<String> monthDays) {

        this.mMonthDays = monthDays;

    }

    public class CalendarViewHolder extends RecyclerView.ViewHolder {
        TextView CalendarSingleItem;
        public CalendarViewHolder(View itemView) {
            super(itemView);
            CalendarSingleItem = (TextView) itemView.findViewById(R.id.calendar_single_item);

        }
    }
}

Layout:

        <GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_row="20"
        android:layout_column="4"
        android:id="@+id/journey_date_picker">
        <TextView
            android:id="@+id/current_month"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:background="@color/ActiveBg"
            android:layout_column="0"
            android:gravity="center"
            android:layout_row="0"
            android:textStyle="bold"
            android:textSize="40sp"
            android:textColor="@color/color_white"
            />
        <TextView
            android:id="@+id/current_date"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:background="@color/ActiveBg"
            android:gravity="center"
            android:layout_column="0"
            android:layout_row="1"
            android:textStyle="bold"
            android:textSize="40sp"
            android:textColor="@color/color_white"
            />
        <TextView
            android:id="@+id/current_year"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:background="@color/ActiveBg"
            android:layout_column="0"
            android:layout_row="2"
            android:gravity="center"
            android:textStyle="bold"
            android:textSize="40sp"
            android:textColor="@color/color_white"
            />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:layout_column="0"
            android:gravity="center"
            android:layout_row="3"
            android:orientation="horizontal">
            <neppro.com.busapp.customView.CustomTextView
                app:cstmFontFace="fontawesome-webfont.ttf"
                android:id="@+id/prev_month"
                android:textSize="30sp"
                android:clickable="true"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:text="@string/icon_prev_month"
                android:layout_marginLeft="@dimen/input_margintop_bottom"
                android:layout_marginRight="@dimen/input_margintop_bottom"
                android:layout_width="wrap_content"
                android:textColor="@color/ActiveBg"
                android:layout_height="wrap_content" />
            <TextView
                android:id="@+id/current_day_month"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="09-aug-2014"
                android:textStyle="bold"
                android:textSize="20sp"
                android:layout_marginLeft="@dimen/common_margin_padding_for_text"
                android:layout_marginRight="@dimen/common_margin_padding_for_text"/>
            <neppro.com.busapp.customView.CustomTextView
                app:cstmFontFace="fontawesome-webfont.ttf"
                android:id="@+id/next_month"
                android:textSize="30sp"
                android:clickable="true"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:layout_marginLeft="@dimen/input_margintop_bottom"
                android:layout_marginRight="@dimen/input_margintop_bottom"
                android:layout_width="wrap_content"
                android:textColor="@color/ActiveBg"
                android:text="@string/icon_next_month"
                android:layout_height="wrap_content" />
        </LinearLayout>
        <android.support.v7.widget.RecyclerView
            android:id="@+id/calendar_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

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

    </GridLayout>

And RecyclerView adapter:

    /*
     * Copyright (c) $today.year.Copyright goes here.
     */

    package neppro.com.busapp.Adapters;

    import android.content.Context;
    import android.support.v7.widget.RecyclerView;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.TextView;

    import java.util.List;
    import java.util.zip.Inflater;

    import neppro.com.busapp.R;
    import neppro.com.busapp.interfaces.DataCarrierForAdapter;
    import neppro.com.busapp.model.BusSearchResultWrapper;

    /**
     * Created by RaazDk on 11/7/2015.
     */
    public class DatePickerAdapter extends RecyclerView.Adapter<DatePickerAdapter.CalendarViewHolder>
    implements DataCarrierForAdapter{
        private List<String> mMonthDays;
        private LayoutInflater layoutInflater;
        public DatePickerAdapter(Context context) {
            layoutInflater = LayoutInflater.from(context);

        }

        @Override
        public CalendarViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View CalendarSingleItem = layoutInflater
                    .inflate(R.layout.calendar_single_date_layout, parent, false);
            CalendarViewHolder holder = new CalendarViewHolder(CalendarSingleItem);
            return  holder;
        }

        @Override
        public void onBindViewHolder(CalendarViewHolder holder, int position) {
            holder.CalendarSingleItem.setText(mMonthDays.get(position).toString());
        }

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

        @Override
        public void busSearchResultDataForAdapter(List<BusSearchResultWrapper.AvailableBus> busList,
                                                  String fromLocation, String toLocation) {

        }

        @Override
        public void navMenuAdapterDataCarrier(Context context, RecyclerView recyclerView,
                                              Object adapterInstance, String[] menuText,
                                              String[] menuIcons) {

        }

        @Override
        public void CalendarDataCarrier(List<String> monthDays) {

            this.mMonthDays = monthDays;

        }

        public class CalendarViewHolder extends RecyclerView.ViewHolder {
            TextView CalendarSingleItem;
            public CalendarViewHolder(View itemView) {
                super(itemView);
                CalendarSingleItem = (TextView) itemView.findViewById(R.id.calendar_single_item);

            }
        }
    }

0 个答案:

没有答案