Hello, I am facing an issue with getSharedPreferences not resolving. I have searched for solutions extensively but nothing seems to fix it. How can I implement getSharedPreferences in onclick inside ViewHolder?
Here is the code snippet from MyHolder.class:
public class MyHolder extends RecyclerView.ViewHolder {
TextView nametxt;
ImageView img;
TextView url;
TextView channel;
Context c;
public MyHolder(View itemView) {
super(itemView);
nametxt= (TextView) itemView.findViewById(R.id.nameTxt);
img= (ImageView) itemView.findViewById(R.id.movieImage);
url= (TextView) itemView.findViewById(R.id.urltxt);
channel= (TextView) itemView.findViewById(R.id.channel);
itemView.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
Intent intent = new Intent(v.getContext(), VideoPlayerActivity.class);
SharedPreferences prefs = getSharedPreferences("My_Prefs", MODE_PRIVATE);
String user = prefs.getString("user", "");
String urls= url.getText().toString()+user+user+channel.getText().toString();
intent.putExtra("urls", urls);
v.getContext().startActivity(intent);
}
});
}
}