I have activity A and B. activity B uses recycle view Adpater to show the the list of information. From activity A, I'm sending intent to activity B which is used for toolbar title. But I also need the same intent in Adapter class also.
So How do I pass intent value from Activity A to B and also use the same intent in adapter class also.
My Activity A has code
Intent new = new Intent(itemView.getContext(), B.class);
phy.putExtra("key","This is title"); itemView.getContext().startActivity(new);
and in Activity B, I have
getSupportActionBar().setTitle(getIntent().getStringExtra("key"));
I want the key value in adapter class also.
The code of Activity B is
public class RoomlistActivity extends AppCompatActivity {
DatabaseReference dbreference,dbref;
RecyclerView rv;
ArrayList<Roompost> list;
private RoomAdapter staggeredBooksAdapter;
ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_subject_books);
list = new ArrayList<>();
staggeredBooksAdapter = new RoomAdapter(list);
rv = (RecyclerView) findViewById(R.id.recyclerView);
rv.setHasFixedSize(true);
LinearLayoutManager llm = new LinearLayoutManager(this);
rv.setLayoutManager(llm);
rv.setAdapter(staggeredBooksAdapter);
}
and my adapter class has
public class RoomAdapter extends RecyclerView.Adapter<RoomAdapter.MyViewHolder> {
ArrayList<Roompost> bookslist;
CardView cv;
Roompost g;
public RoomAdapter(ArrayList<Roompost> bookslist){
this.bookslist = bookslist;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout,parent,false);
return new MyViewHolder(v);
}
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView bookName,sellername,profile_details,update_info;
Button mSolved;
ImageView iv;
MyViewHolder(final View itemView) {
super(itemView);
cv = (CardView) itemView.findViewById(R.id.my_card_view);
update_info =(TextView) itemView.findViewById(R.id.update_info);
}
}
@Override
public int getItemCount() {
return bookslist.size();
}
}
Thanks in advance.
Just add 1 more parameter in your adapter and pass the title
public RoomAdapter(ArrayList<Roompost> bookslist, String title){
this.bookslist = bookslist;
this.title = title;
}
And in your Activity B onCreate
String title = getIntent().getStringExtra("key");
staggeredBooksAdapter = new RoomAdapter(list, title);