当我点击Recycler启动新活动中的项目时,我有包含RecyclerView的活动,我的问题是当回到RecyclerView活动时我需要显示点击了哪个项目,所以我必须停止完成RecyclerView活动,< / p>
注意:当用户点击项目i时,使用图片视图显示并隐藏检查项目,当用户点击图片视图显示时,有什么想法吗?
这是我的RecyclerView适配器
public class ScreenRecyclerAdapter extends RecyclerView.Adapter<ScreenRecyclerAdapter.ViewHolder> {
Context context;
String image_list[];
List<ImageView> items;
String chiliSharedpreferences = "chiliSharedpreferences";
public ScreenRecyclerAdapter(String[] image_list, Context context){
super();
this.image_list = image_list;
this.context = context;
this.items = new ArrayList<>();}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.screen_items, parent, false);
ViewHolder viewHolder = new ViewHolder(v);
return viewHolder;}
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
holder.location_text_view.setText(image_list[position]);
items.add(holder.check_image_view);
}
@Override
public int getItemCount() {
return image_list.length;
}
class ViewHolder extends RecyclerView.ViewHolder{
ImageView check_image_view ;
TextView location_text_view;
LinearLayout linear;
CardView loactionCardView;
public ViewHolder(View itemView) {
super(itemView);
check_image_view = (ImageView) itemView.findViewById(R.id.check_image_view);
location_text_view = (TextView) itemView.findViewById(R.id.location_text_view);
linear = (LinearLayout) itemView.findViewById(R.id.linear);
loactionCardView = (CardView) itemView.findViewById(R.id.cv);
loactionCardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MakeAllInvisbale();
check_image_view.setVisibility(View.VISIBLE);
Intent intent = new Intent(context,MainActivity.class);
context.startActivity(intent);
SharedPreferences shared = context.getSharedPreferences(chiliSharedpreferences, MODE_PRIVATE);
SharedPreferences.Editor editor = shared.edit();
editor.putString("screenId","id1");
editor.commit();
}
});}}
private void MakeAllInvisbale() {
for(ImageView item : items) {
item.setVisibility(View.INVISIBLE);}}}
答案 0 :(得分:0)
您可以保存到SharedPreferences
点击的查看位置
editor.putInt("SAVED_CLICKED_ITEM", getPosition());
和ckeck每次都保存位置,像这样:
SharedPreferences shared = context.getSharedPreferences(chiliSharedpreferences, MODE_PRIVATE);
int position = shared.getInt("SAVED_CLICKED_ITEM", getPosition());
if (position == getPosition()) {
// do what you want
}