Мне нужно сделать копию следующего RecyclerView
:
RecyclerView
содержит список Schedule
объектов. Когда я нажимаю на звезду, я хочу изменить ее цвет. Когда я нажимаю на текст, я хочу открыть новый Activity
с более подробной информацией о Schedule
.
. В своей деятельности я хочу использовать следующие методы:
//method which gets executed when I click on a star
OnStarClick()
{
//Get Schedule id
//Get reference of the star so I can change its color
}
//method which gets executed when I click on a text
OnTextClicked()
{
//Get Schedule id
}
Здесь моя деятельность:
public class SchedulesActivity : BaseActivity
{
RecyclerView schedulesRecyclerView;
RecyclerView.LayoutManager schedulesLayoutManager;
SchedulesAdapter schedulesAdapter;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.SchedulesActivity);
List<Schedule> schedules = //Get it from database
schedulesRecyclerView = FindViewById<RecyclerView>(Resource.Id.schedulesRecyclerView);
schedulesLayoutManager = new LinearLayoutManager(this);
schedulesRecyclerView.SetLayoutManager(schedulesLayoutManager);
schedulesAdapter = new SchedulesAdapter(schedules);
schedulesRecyclerView.SetAdapter(schedulesAdapter);
}
OnStarClicked()
{
}
OnTextClicked()
{
}
}
Вот модель Schedule
:
public class Schedule
{
public int Id { get; set; }
public string Day { get; set; }
public string Hour { get; set; }
public string ShortDescription { get; set; }
public string LongDescription { get; set; }
}
Вот мой ViewHolder
:
public class ScheduleViewHolder : RecyclerView.ViewHolder
{
public ImageView starImageView { get; private set; }
public TextView hourAndScheduleTextView { get; private set; }
// Get references to the views defined in the CardView layout.
public ScheduleViewHolder(View itemView)
: base(itemView)
{
// Locate and cache view references:
starImageView = itemView.FindViewById<ImageView>(Resource.Id.starImageView);
hourAndScheduleTextView = itemView.FindViewById<TextView>(Resource.Id.hourAndScheduleTextView);
}
}
Вот мой адаптер :
public class SchedulesAdapter : RecyclerView.Adapter
{
public List<Schedule> listOfSchedules;
public SchedulesAdapter(List<Schedule> schedules)
{
listOfSchedules = schedules;
}
public override int ItemCount
{
get { return listOfSchedules.Count; }
}
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
ScheduleViewHolder vh = holder as ScheduleViewHolder;
vh.hourAndScheduleTextView.Text = /*listOfSchedules[position].Hour + " " + */listOfSchedules[position].ShortDescription;
}
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
{
View itemView = LayoutInflater.From(parent.Context).
Inflate(Resource.Layout.ScheduleCardView, parent, false);
ScheduleViewHolder vh = new ScheduleViewHolder(itemView);
return vh;
}
}