Я все еще новичок в Java, но я учусь, по крайней мере, вносить изменения в существующий код.
У меня есть приложение, разработанное кем-то другим, и я просто вношу небольшие изменения в Это. Я пытаюсь установить Textview
«Недавно добавленные», чтобы его можно было щелкнуть и изменить на «По дате» и обратно, тогда у меня будет изменение API в соответствии с этим. Если мне помогут узнать, где поставить onClickListener
, думаю, я смогу его достать ....
Скриншот
Если бы кто-нибудь мог мне помочь, я был бы очень признателен. Вот код для PreachingAdapter. java
package com.churchofgod.adapter;
public class PreachingAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
public List<LandingData.SermonsData> items;
public Listpackage<LandingData.PodcastsData> items1;
public List<LandingData.SingingsData> items2;
public List<LandingData.SundaySchoolsData> items3;
Context context;
int headerType;
private static final int HEADER_VIEW = 1;
public static class PreachingHeaderViewHolder extends RecyclerView.ViewHolder {
FrameLayout viewApostlesLayout, viewOrdainedMinistersLayout, viewLocationsLayout;
PreachingHeaderViewHolder(View itemView) {
super(itemView);
viewApostlesLayout = itemView.findViewById(R.id.viewApostlesLayout);
viewOrdainedMinistersLayout = itemView.findViewById(R.id.viewOrdainedMinistersLayout);
//viewMinistersLayout = (FrameLayout) itemView.findViewById(R.id.viewMinistersLayout);
viewLocationsLayout = itemView.findViewById(R.id.viewLocationsLayout);
}
}
public static class SundaySchoolsHeaderViewHolder extends RecyclerView.ViewHolder {
FrameLayout viewApostlesLayout, viewOrdainedMinistersLayout, viewLocationsLayout;
SundaySchoolsHeaderViewHolder(View itemView) {
super(itemView);
viewApostlesLayout = itemView.findViewById(R.id.viewApostlesLayout);
viewOrdainedMinistersLayout = itemView.findViewById(R.id.viewOrdainedMinistersLayout);
//viewMinistersLayout = (FrameLayout) itemView.findViewById(R.id.viewMinistersLayout);
viewLocationsLayout = itemView.findViewById(R.id.viewLocationsLayout);
}
}
public static class SingingHeaderViewHolder extends RecyclerView.ViewHolder {
FrameLayout viewLocationsLayout;
SingingHeaderViewHolder(View itemView) {
super(itemView);
viewLocationsLayout = itemView.findViewById(R.id.viewLocationsLayout);
}
}
public static class ItemViewHolder extends RecyclerView.ViewHolder {
CardView cardView;
ImageView img;
TextView tvTitle;
TextView tvDesc;
ItemViewHolder(View itemView) {
super(itemView);
cardView = itemView.findViewById(R.id.cardView);
img = itemView.findViewById(R.id.img);
tvTitle = itemView.findViewById(R.id.tvTitle);
tvDesc = itemView.findViewById(R.id.tvDesc);
}
}
public PreachingAdapter(List<LandingData.SermonsData> items, Context context, int headerType){
this.items = items;
this.context = context;
this.headerType = headerType;
}
@Override
public int getItemCount() {
if (headerType == 0) {
return items1.size();
} else if (headerType == 1 ){
if (items.size() == 0) {
return 1;
} else {
return items.size() + 1;
}
}
else if (headerType == 3)
{
return items.size();
}
else if (headerType == 4)
{
return items3.size();
}
else {
return items2.size() + 1;
}
}
@Override
public int getItemViewType(int position) {
if (headerType == 0) {
return super.getItemViewType(position);
} else if (headerType == 3)
{
return items.size();
} else if (headerType == 4)
{
return items3.size();
}
else {
if (position == 0) {
return HEADER_VIEW;
} else {
return super.getItemViewType(position);
}
}
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
if (viewType == HEADER_VIEW) {
if (headerType == 1) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.adapter_all_preaching_header, viewGroup, false);
PreachingAdapter.PreachingHeaderViewHolder preachingHeaderViewHolder = new PreachingAdapter.PreachingHeaderViewHolder(view);
return preachingHeaderViewHolder;
}else if (headerType == 4) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.adapter_all_teaching_header, viewGroup, false);
PreachingAdapter.SundaySchoolsHeaderViewHolder sundaySchoolsHeaderViewHolder = new PreachingAdapter.SundaySchoolsHeaderViewHolder(view);
return sundaySchoolsHeaderViewHolder;
} else {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.adapter_all_singing_header, viewGroup, false);
PreachingAdapter.SingingHeaderViewHolder singingHeaderViewHolder = new PreachingAdapter.SingingHeaderViewHolder(view);
return singingHeaderViewHolder;
}
} else {
Viepackagew view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.adapter_preaching, viewGroup, false);
PreachingAdapter.ItemViewHolder itemViewHolder = new PreachingAdapter.ItemViewHolder(view);
return itemViewHolder;
}
}
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder viewHolder, final int i) {
try {
if (viewHolder instanceof ItemViewHolder) {
PreachingAdapter.ItemViewHolder itemViewHolder = (PreachingAdapter.ItemViewHolder) viewHolder;
String imgUrl = "" ,title = "" ,desc = "";
if (headerType == 1 || headerType == 3) //||headerType == 4)//sermons
{
LandingData.SermonsData data = items.get(headerType==3?i:i-1);
imgUrl = data.artists.get(0).image;
title = data.title;
if (data.artists.size() >= 2){
String firstMinister = data.artists.get(0).name;
String secondMinister = data.artists.get(1).name;
packagepackage desc = firstMinister + " & " + secondMinister;
}else{
desc = data.artists.get(0).name;
}
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, NowPlayingActivity.class);
CurrentPlaying.stopSimpleExoPlayer();
intent.putExtra("data",items.get(headerType==3?i:i-1));
context.startActivity(intent);
}
});
}
else if (headerType == 4)
{
LandingData.SundaySchoolsData data = items3.get(headerType==4?i:i-1);
imgUrl = data.artists.get(0).image;
title = data.title;
if (data.artists.size() >= 2){
String firstMinister = data.artists.get(0).name;
String secondMinister = data.artists.get(1).name;
desc = firstMinister + " & " + secondMinister;
}else{
desc = data.artists.get(0).name;
}
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, NowPlayingActivity.class);
CurrentPlaying.stopSimpleExoPlayer();
intent.putExtra("data",items3.get(headerType==4?i:i-1));
context.startActivity(intent);
}
});
}
else if (headerType == 0)//pod casts
{
package LandingData.PodcastsData data = items1.get(i);
imgUrl = data.image;
title = data.title;
desc = data.title;
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, NowPlayingActivity.class);
CurrentPlaying.stopSimpleExoPlayer();
intent.putExtra("data", items1.get(i));
context.startActivity(intent);
}
});
}
else {//singings
final LandingData.SingingsData data = items2.get(i - 1);
imgUrl = data.image;
title = data.title;
desc = data.description;
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, PlaylistActivity.class);
intent.putExtra("data",data);
context.startActivity(intent);
}
});
}
Glide.with(context).load(imgUrl).into(itemViewHolder.img);
itemViewHolder.tvTitle.setText(title);
itemViewHolder.tvDesc.setText(desc);
} else if (viewHolder instanceof PreachingHeaderViewHolder) {
PreachingAdapter.PreachingHeaderViewHolder headerViewHolder = (PreachingAdapter.PreachingHeaderViewHolder) viewHolder;
headerViewHolder.viewLocationsLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, LocationsActivity.class);
intent.putExtra("sermon", true);
context.startActivity(intent);
}
});
headerViewHolder.viewApostlesLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, MembersActivity.class);
intent.putExtra("TYPE", "Apostles");
context.startActivity(intent);
}
});
headerViewHolder.viewOrdainedMinistersLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, MembersActivity.class);
intent.putExtra("TYPE", "Ordained Ministers");
context.startActivity(intent);
}
});
} else if (viewHolder instanceof SundaySchoolsHeaderViewHolder) {
PreachingAdapter.SundaySchoolsHeaderViewHolder headerViewHolder = (PreachingAdapter.SundaySchoolsHeaderViewHolder) viewHolder;
headerViewHolder.viewLocationsLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, LocationsActivity.class);
intent.putExtra("sermon",true);
context.startActivity(intent);
}
});
headerViewHolder.viewApostlesLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, MembersActivity.class);
intent.putExtra("TYPE","Apostles");
context.startActivity(intent);
}
});
headerViewHolder.viewOrdainedMinistersLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, MembersActivity.class);
intent.putExtra("TYPE","Ordained Ministers");
context.startActivity(intent);
}
});
} else if (viewHolder instanceof SingingHeaderViewHolder) {
PreachingAdapter.SingingHeaderViewHolder headerViewHolder = (PreachingAdapter.SingingHeaderViewHolder) viewHolder;
headerViewHolder.viewLocationsLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, LocationsActivity.class);
intent.putExtra("sermon",false);
context.startActivity(intent);
}
});
}
} catch (Exception e) {
}
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
public class ViewHolder extends RecyclerView.ViewHolder {
public ViewHolder(View itemView) {
super(itemView);
}
public void bindView(int position) {
}
}
}
Вот что я сделал в ответ на предложенную помощь
public static class SundaySchoolsHeaderViewHolder extends RecyclerView.ViewHolder {
FrameLayout viewApostlesLayout, viewOrdainedMinistersLayout, viewLocationsLayout;
SundaySchoolsHeaderViewHolder(View itemView) {
super(itemView);
viewApostlesLayout = itemView.findViewById(R.id.viewApostlesLayout);
viewOrdainedMinistersLayout = itemView.findViewById(R.id.viewOrdainedMinistersLayout);
//viewMinistersLayout = (FrameLayout) itemView.findViewById(R.id.viewMinistersLayout);
viewLocationsLayout = itemView.findViewById(R.id.viewLocationsLayout);
}
}
public static class SortByViewHolder extends RecyclerView.ViewHolder {
public TextView simpleTextView;
SortByViewHolder (View itemView) {
super(itemView);
simpleTextView= itemView.findViewById(R.id.sort);
}
}
public static class SingingHeaderViewHolder extends RecyclerView.ViewHolder {
FrameLayout viewLocationsLayout;
SingingHeaderViewHolder(View itemView) {
super(itemView);
viewLocationsLayout = itemView.findViewById(R.id.viewLocationsLayout);
}
}
и
}
});
} else if (viewHolder instanceof SingingHeaderViewHolder) {
PreachingAdapter.SingingHeaderViewHolder headerViewHolder = (PreachingAdapter.SingingHeaderViewHolder) viewHolder;
headerViewHolder.viewLocationsLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, LocationsActivity.class);
intent.putExtra("sermon",false);
context.startActivity(intent);
}
});
}
if (viewHolder instanceof SortByViewHolder ) {
((SortByViewHolder) viewHolder).simpleTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, LocationsActivity.class);
context.startActivity(intent);
}
});
}
} catch (Exception e) {
}
}