你好我有getSharedPreferences無法解決,我搜索很多答案,但任何解決這個問題。 如何在onclick iside ViewHolder中實現getSharedPreferences?Android - getSharedPreferences無法解析
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);
}
});
}
}
使用'context.getSharedPreferences
context
(「My_Prefs」,MODE_PRIVATE);' – akhilesh0707