我試圖從一個適配器,這將使我的信息建立一個集電視節目cardview傳遞信息。無法從適配器傳遞的Intent中獲得額外功能?
我的價值觀。然而所有正在返回空。
這裏是我的適配器代碼(有問題的代碼是在第3個case語句MyMenuItemClickListener)
public class TvShowSeasonsAdapter extends RecyclerView.Adapter<TvShowSeasonsAdapter.MyViewHolder> {
private Context mContext;
private List<Season> seasonList;
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView tvShowTitle,season, episodes;
public ImageView thumbnail, overflow;
public MyViewHolder(View view) {
super(view);
tvShowTitle = (TextView) view.findViewById(R.id.tvShowTitle);
season = (TextView) view.findViewById(R.id.Season);
episodes = (TextView) view.findViewById(R.id.Episodes);
thumbnail = (ImageView) view.findViewById(R.id.thumbnail);
overflow = (ImageView) view.findViewById(R.id.overflow);
}
}
public TvShowSeasonsAdapter(Context mContext, List<Season> seasonList) {
this.mContext = mContext;
this.seasonList = seasonList;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.tvshow_seasoncard, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {
Season tvshowSeason = seasonList.get(position);
holder.tvShowTitle.setText(tvshowSeason.getTvShowName());
holder.season.setText("Season " + tvshowSeason.getSeasonNumber());
holder.episodes.setText("No of Episodes :" + tvshowSeason.getEpisodeCount());
// loading TV show poster using Glide library
Glide.with(mContext).load(tvshowSeason.getPosterPath()).into(holder.thumbnail);
holder.overflow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showPopupMenu(holder.overflow, position);
}
});
}
/**
* Showing popup menu when tapping on 3 dots
*/
private void showPopupMenu(View view, int position) {
// inflate menu
PopupMenu popup = new PopupMenu(mContext, view);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.menu_tvshowseasonsadapter, popup.getMenu());
popup.setOnMenuItemClickListener(new MyMenuItemClickListener(position));
popup.show();
}
/**
* Click listener for popup menu items
*/
class MyMenuItemClickListener implements PopupMenu.OnMenuItemClickListener {
int position;
public MyMenuItemClickListener(int position) {
this.position=position;
}
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
Intent intent;
switch (menuItem.getItemId()) {
case R.id.go_to_Popular:
Toast.makeText(mContext, "Go back to Popular", Toast.LENGTH_SHORT).show();
intent = new Intent(mContext,PopularActivity.class);
mContext.startActivity(intent);
Toast.makeText(mContext, "Add to Favourites", Toast.LENGTH_SHORT).show();
return true;
case R.id.back_to_favourites:
Toast.makeText(mContext, "Go to Favourites", Toast.LENGTH_SHORT).show();
/*
TODO - Need to make sure there is at least one favourite selected before allowing the
the user to go to the favourite activity. */
// Need to use mContext since in menu listener
intent = new Intent(mContext, FavouriteActivity.class);
mContext.startActivity(intent);
return true;
case R.id.view_episodes:
intent = new Intent(mContext, WhereWazzaEpisodes.class);
Intent intentContents = ((Activity) mContext).getIntent();
int seasonForEpisodes = seasonList.get(position).getSeasonNumber();
int amountOfEp = seasonList.get(position).getEpisodeCount();
int tvShowId = intentContents.getIntExtra("favTvShowID",0);
intent.putExtra("seasonNumber", seasonForEpisodes);
intent.putExtra("tvShowId", tvShowId);
intent.putExtra("episodeCount", amountOfEp);
mContext.startActivity(intent);
return true;
default:
}
return false;
}
}
@Override
public int getItemCount() {
return seasonList.size();
}
}
這裏是我的onCreate方法活動代碼:
super.onCreate(savedInstanceState);
setContentView(R.layout.episode_list);
Intent intent=getIntent();
Bundle extras = getIntent().getExtras();
String tvShowID = extras.getString("favTvShowID");
Log.d("TVSHOW_ID", tvShowID);
String seasonNumber = extras.getString("seasonNumber");
Log.d("TVSHOW_SEASONNUM", seasonNumber);
String episodeCount = extras.getString("episodeCount");
Log.d("TVSHOW_EPISODE", episodeCount);
我都試過包和意圖嘗試,看看是否有任何區別,但他們仍然返回null。
th你的名單上的值是什麼意思? –
我認爲你的演員陣容是空的。一旦嘗試使用靜態數據。 – Rajasekhar
你得到任何錯誤? –