I want to display the data based on the scheduled date saved on the database, i tried comparing it to the current date of the device, but it didn't work. This is my saved data from firebase:
This is the Logcat
This is the Adapter class:
public class ListAdapter extends RecyclerView.Adapter<ListAdapter.MyViewHolder> {
Context context;
ArrayList<Reminder> list;
public ListAdapter(Context context, ArrayList<Reminder> list) {
this.context = context;
this.list = list;
}
#NonNull
#Override
public MyViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(context).inflate(R.layout.item, parent, false);
return new MyViewHolder(v);
}
#Override
public void onBindViewHolder(#NonNull MyViewHolder holder, int position) {
Reminder Reminder = list.get(position);
holder.t.setText(Reminder.gett());
holder.d.setText(Reminder.getd());
holder.tm.setText(Reminder.gettm());
holder.dt.setText(Reminder.getdt());
holder.currentDate.setText(Reminder.getcurrentDate());
}
#Override
public int getItemCount() {
return list.size();
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
TextView t, d, tm, dt, currentDate;
public MyViewHolder(#NonNull View itemView) {
super(itemView);
t = itemView.findViewById(R.id.tvtitle);
d = itemView.findViewById(R.id.tvdesc);
tm = itemView.findViewById(R.id.tvtime);
dt = itemView.findViewById(R.id.tvdate);
currentDate = itemView.findViewById(R.id.tvcdate);
}
}
}
This is my code to retrieve the data from the database:
public class ReminderMainActivity extends AppCompatActivity {
RecyclerView recyclerView;
DatabaseReference database;
Calendar calendar = Calendar.getInstance();
String currentdate = DateFormat.getDateInstance().format(calendar.getTime());
com.example.luntian.adapter.ListAdapter ListAdapter;
ArrayList<Reminder> list;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_reminder_main);
recyclerView = findViewById(R.id.userList);
database = FirebaseDatabase.getInstance().getReference("Reminder");
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
list = new ArrayList<Reminder>();
ListAdapter = new ListAdapter(this,list);
recyclerView.setAdapter(ListAdapter);
database.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
for (DataSnapshot dataSnapshot : snapshot.getChildren()) {
Reminder reminder = dataSnapshot.getValue(Reminder.class);
list.add(reminder);
}
ListAdapter.notifyDataSetChanged();
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
}
});
Related
Basically I want to create a parent recyclerView which shows the categories and the child recyclerView shows the books of that specific category. But the result of my code is giving me the same books for all categories. Below is the necessary code attached.
Java Source Code for home fragment adapter call
private void loadCategories() {
//init arrayList
categoryArrayList = new ArrayList<>();
//get all categories from firebase
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("Categories");
ref.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
//clear arrayList before adding data to it
categoryArrayList.clear();
for (DataSnapshot ds : snapshot.getChildren()) {
//get data
ModelCategory model = ds.getValue(ModelCategory.class);
//add category to arrayList
categoryArrayList.add(model);
}
//setup adapter
adapterCategoryHome = new AdapterCategoryHome(categoryArrayList);
//set adapter to recyclerView
binding.categoryRv.setAdapter(adapterCategoryHome);
adapterCategoryHome.notifyDataSetChanged();
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
}
});
}
Parent Adapter
public class AdapterCategoryHome extends RecyclerView.Adapter<AdapterCategoryHome.HolderCategory> {
private Context context;
public ArrayList<ModelCategory> categoryArrayList;
public static final String TAG = "CATEGORY_HOME_TAG";
//arrayList to hold data of type ModelPdf
private ArrayList<ModelPdf> pdfArrayList;
private AdapterPdfHome adapterPdfHome;
public AdapterCategoryHome(ArrayList<ModelCategory> categoryArrayList) {
this.categoryArrayList = categoryArrayList;
}
#NonNull
#Override
public HolderCategory onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
//bind view of row_category_home.xml
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_category_home, parent, false);
this.context = parent.getContext();
return new HolderCategory(view);
}
#Override
public void onBindViewHolder(#NonNull AdapterCategoryHome.HolderCategory holder, int position) {
//get data
ModelCategory model = categoryArrayList.get(position);
String id = model.getId();
String category = model.getCategory();
String uid = model.getUid();
long timestamp = model.getTimestamp();
Log.d(TAG, "onBindViewHolder: "+category);
//set data
holder.categoryTv.setText(category);
loadPdfList(model, holder);
}
private void loadPdfList(ModelCategory model, HolderCategory holder) {
//init list before adding data
pdfArrayList = new ArrayList<>();
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("Books");
ref.orderByChild("categoryId").equalTo(model.getId())
.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
pdfArrayList.clear();
for (DataSnapshot ds : snapshot.getChildren()) {
//get data
ModelPdf model = ds.getValue(ModelPdf.class);
//add to list
pdfArrayList.add(model);
}
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false);
holder.bookRv.setHasFixedSize(true);
Log.d(TAG, "pdf size: " + pdfArrayList.size() + model.getCategory() + holder.categoryTv.getText()+ holder.categoryTv.getContext());
//setup adapter
adapterPdfHome = new AdapterPdfHome(holder.bookRv.getContext(), pdfArrayList);
holder.bookRv.setLayoutManager(layoutManager);
holder.bookRv.setAdapter(adapterPdfHome);
adapterPdfHome.notifyDataSetChanged();
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
}
});
}
#Override
public int getItemCount() {
return categoryArrayList.size();
}
/*View Holder class to hold UI views for row_category.xml*/
class HolderCategory extends RecyclerView.ViewHolder {
//ui views of row_category.xml
TextView categoryTv;
RecyclerView bookRv;
public HolderCategory(#NonNull View itemView) {
super(itemView);
//init ui views
categoryTv = itemView.findViewById(R.id.categoryTv);
bookRv = itemView.findViewById(R.id.bookRv);
}
}
}
Child Adapter
public class AdapterPdfHome extends RecyclerView.Adapter<AdapterPdfHome.HolderPdfAdmin> {
//context
private Context context;
//arrayList to hold list of data of type modelPdf
public ArrayList<ModelPdf> pdfArrayList;
private FilterPdfAdmin filter;
private static final String TAG = "PDF_ADAPTER_TAG";
//progress dialog
private ProgressDialog progressDialog;
//constructor of above
public AdapterPdfHome(Context context, ArrayList<ModelPdf> pdfArrayList) {
this.context = context;
this.pdfArrayList = pdfArrayList;
Log.d(TAG, "AdapterPdfHome: "+pdfArrayList.size());
//init progress dialog
progressDialog = new ProgressDialog(context);
progressDialog.setTitle("Please Wait");
progressDialog.setCanceledOnTouchOutside(false);
}
#NonNull
#Override
public HolderPdfAdmin onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
//bind view of row_pdf_admin.xml
View view = LayoutInflater.from(context).inflate(R.layout.row_pdf_home,parent,false);
return new HolderPdfAdmin(view);
}
#Override
public void onBindViewHolder(#NonNull AdapterPdfHome.HolderPdfAdmin holder, int position) {
/*Get data, Set Data, handle clicks, etc.*/
//get data
ModelPdf model = pdfArrayList.get(position);
String title = model.getTitle();
String author = model.getAuthor();
Log.d(TAG, "onBindViewHolder: "+title);
//set data
holder.titleTv.setText(title);
holder.authorTv.setText(author);
Glide.with(context)
.load(model.getCoverPageUrl())
.placeholder(R.drawable.back01)
.into(holder.pdfIv);
}
#Override
public int getItemCount() {
//return size of arrayList
return pdfArrayList.size();
}
/*view holder class for row_pdf_user.xml*/
class HolderPdfAdmin extends RecyclerView.ViewHolder {
//UI views of row_pdf_admin.xml
TextView titleTv, authorTv;
ImageView pdfIv;
public HolderPdfAdmin(#NonNull View itemView) {
super(itemView);
//init ui views
titleTv = itemView.findViewById(R.id.titleTv);
authorTv = itemView.findViewById(R.id.authorTv);
pdfIv = itemView.findViewById(R.id.pdfIv);
}
}
}
move "private AdapterPdfHome adapterPdfHome;" to "onBindViewHolder"
I have created a simple notes app in which I'm storing data in firebase. Showing the list of notes(time and few words of a note) in recyclerview. Now I want when I click in a particular note, it take to different activity where the details of the note will be shown. I am not able to get data from firebase column wise(note and time).
CustomAdapter
Here I'm sending the position of the item clicked to NotesDetails class
public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.MyViewHolder> {
Context context;
ArrayList<Model> models;
public CustomAdapter(Context context, ArrayList<Model> models){
this.context = context;
this.models = models;
}
#Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.list_content, parent, false);
return new MyViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull MyViewHolder holder, int position) {
holder.time_text.setText(models.get(holder.getBindingAdapterPosition()).getText());
holder.string_text.setText(models.get(holder.getBindingAdapterPosition()).getNotes());
holder.constraintLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context.getApplicationContext(), NotesDetails.class);
intent.putExtra("position", String.valueOf(holder.getBindingAdapterPosition()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
});
}
#Override
public int getItemCount() { return models.size(); }
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView string_text, time_text;
ConstraintLayout constraintLayout;
public MyViewHolder(View itemView) {
super(itemView);
string_text = itemView.findViewById(R.id.textView);
time_text = itemView.findViewById(R.id.timeshow);
constraintLayout = itemView.findViewById(R.id.constraintLayout);
}
}
}
NotesDetails
I want to show time and details of particular item here in testShow and timeShow
public class NotesDetails extends AppCompatActivity {
ArrayList<Model> models;
TextView textShow, timeShow;
DBHelper myDB;
DatabaseReference dbReference;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notes_details);
textShow = findViewById(R.id.notesShow);
timeShow = findViewById(R.id.timeshow);
myDB = new DBHelper(this);
Intent intent = getIntent();
int position = Integer.parseInt(intent.getStringExtra("position"));
dbReference = FirebaseDatabase.getInstance().getReference("Model").child("notes");
dbReference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull #NotNull DataSnapshot snapshot) {
for(DataSnapshot dataSnapshot: snapshot.getChildren()){
Model m1 = dataSnapshot.getValue(Model.class);
textShow.setText((CharSequence) m1);
}
}
#Override
public void onCancelled(#NonNull #NotNull DatabaseError error) {
}
});
}
}
I have two Models (ModelChat and ModelUsers) and their class adapters (PostsAdapter and AllUsersAdapter).
I want to get and set user info such as name and email from the ModelUser and get and set post information from the ModelPost from Firebase database into the same recyclerview in my HomeActivity.
The codes are as shown below:
PostsAdapter.java
public class PostsAdapter extends RecyclerView.Adapter<PostsAdapter.MyHolder>{
Context context;
List<ModelPost> postList;
public PostsAdapter(Context context, List<ModelPost> postList) {
this.context = context;
this.postList = postList;
}
#NonNull
#Override
public MyHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
//inflate layout row_post.xml
View view = LayoutInflater.from(context).inflate(R.layout.row_posts, parent, false);
return new MyHolder(view);
}
#Override
public void onBindViewHolder(#NonNull MyHolder holder, int position) {
//get data
String userUID = postList.get(position).getUserUID();
String userEmail = postList.get(position).getUserEmail();
String userProfilePic = postList.get(position).getUserProfilePic();
String firstName = postList.get(position).getUserFirstName();
String lastName = postList.get(position).getUserLastName();
String userNickName = postList.get(position).getUserNickName();
String postTimeStamp = postList.get(position).getPostTime();
String userPost = postList.get(position).getUserPost();
//set data
//set data
Glide
.with(context)
.load(userProfilePic)
.apply(RequestOptions.circleCropTransform())
.into(holder.avatarTv);
holder.firstnameTv.setText(firstName);
holder.lastnameTv.setText(lastName);
holder.nicknameTv.setText(userNickName);
}
#Override
public int getItemCount() {
return postList.size();
}
//view holder class
class MyHolder extends RecyclerView.ViewHolder {
//views from row_posts layout
public MyHolder(#NonNull View itemView) {
super(itemView);
//init view
//my views here
}
}
}
AllUsersAdapter.java
public class AllUsersAdapter extends RecyclerView.Adapter<AllUsersAdapter.MyHolder>{
Context context;
List<ModelUser> userList;
//Constructor > Generate
public AllUsersAdapter(Context context, List<ModelUser> userList) {
this.context = context;
this.userList = userList;
}
#NonNull
#Override
public MyHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
//Inflate layout (row_user)
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_all_users, parent, false);
return new MyHolder(view);
}
#Override
public void onBindViewHolder(#NonNull MyHolder holder, int position) {
//get data
String userUID = userList.get(position).getUid();
String userProfilePic = userList.get(position).getProfilepic();
String userName = userList.get(position).getFirstname() + " " + userList.get(position).getLastname();
String userNickname = userList.get(position).getNickname();
String userStatus = userList.get(position).getStatus();
//set data
Glide
.with(context)
.load(userProfilePic)
.apply(RequestOptions.circleCropTransform())
.into(holder.mAvatarIv);
holder.mNameTv.setText(userName);
holder.mNicknameTv.setText(userNickname);
holder.mStatusTv.setText(userStatus);
//Handle item click
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
/*Click user from user list to start conversation
*Start Activity by putting UID of receiver
*we will use that UID to identify the user we are gonna chat */
Intent intent = new Intent(context, MessageActivity.class);
intent.putExtra("userUid", userUID);
context.startActivity(intent);
}
});
}
#Override
public int getItemCount() {
return userList.size();
}
class MyHolder extends RecyclerView.ViewHolder {
public MyHolder(#NonNull View itemView) {
super(itemView);
//init my views here
}
}
}
HomeActivity.java
public class HomeActivity extends AppCompatActivity {
FirebaseAuth firebaseAuth;
RecyclerView recyclerView;
List<ModelPost> postList;
PostsAdapter postsAdapter;
String mUID;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
firebaseAuth = FirebaseAuth.getInstance();
//recyclerview and its properties
recyclerView = findViewById(R.id.posts_recyclerview);
//init post list
postList = new ArrayList<>();
loadPosts();
}
private void loadPosts() {
//path of all posts
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Posts");
//get all data from this reference
reference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
postList.clear();
for (DataSnapshot ds: snapshot.getChildren()) {
ModelPost modelPost = ds.getValue(ModelPost.class);
postList.add(modelPost);
//adapter
postsAdapter = new PostsAdapter(HomeActivity.this, postList);
//set adapter to recyclerview
recyclerView.setAdapter(postsAdapter);
}
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
//in case of errors
//Toast.makeText(HomeActivity.this, ""+error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}
Try using ConcatAdapter.
An RecyclerView.Adapter implementation that presents the contents of multiple adapters in sequence. More info
Concatenate adapters sequentially with ConcatAdapter:
https://medium.com/androiddevelopers/merge-adapters-sequentially-with-mergeadapter-294d2942127a
I think this will help
MyAdapter adapter1 = ...;
AnotherAdapter adapter2 = ...;
ConcatAdapter concatenated = new ConcatAdapter(adapter1, adapter2);
recyclerView.setAdapter(concatenated);
My recyclerview always reset to first position after new data is inserted to firebase. In my TestAdapter class, I have an onClickListener which increments like on a post when clicked. Whenever I click on this "like" button, view is reset to first position. I believe this issue is related to setAdapter() being called on data changed. Please help!
MainActivity fetches "post" data from Firebase and populates it in TestAdapter class.
public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private TestAdapter testAdapter;
private ArrayList<Post> postList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
fetchPostFromDB();
}
private void fetchPostFromDB() {
DatabaseReference databaseRef = FirebaseDatabase.getInstance().getReference("Post");
databaseRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
postList = new ArrayList<>();
for (DataSnapshot snap : snapshot.getChildren()) {
String post = snap.child("post").getValue().toString();
Post post = new Post(post);
postList.add(post);
}
testAdapter = new TestAdapter(getApplicationContext(), postList);
recyclerView.setAdapter(testAdapter);
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
}
});
}
TestAdapter binds the data (postList) and has an onClickListener.
public class TestAdapter extends RecyclerView.Adapter<TestAdapter.TestHolder> {
private List<Post> postList;
private Context context;
private DatabaseReference databaseReference;
public TestAdapter(Context ct, ArrayList<Post> postList) {
context = ct;
this.postList = postList;
}
#NonNull
#Override
public TestHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(context);
View view = layoutInflater.inflate(R.layout.post_item, parent, false);
final TestHolder holder = new TestHolder(view);
holder.ibLike.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String postID = postList.get(holder.getAdapterPosition()).getPostID();
databaseReference = FirebaseDatabase.getInstance().getReference("Posts").child(postID).child("likes");
int incrementLike = postList.get(holder.getAdapterPosition()).getLikes() + 1;
databaseReference.setValue(incrementLike);
}
});
return holder;
}
#Override
public void onBindViewHolder(#NonNull final TestHolder holder, final int position) {
holder.tvPost.setText(postList.get(position).getPost());
holder.tvVotes.setText(Integer.toString(postList.get(position).getLikes()));
}
#Override
public int getItemCount() {
return postList.size();
}
public static class TestHolder extends RecyclerView.ViewHolder {
TextView tvPost, tvLikes;
ImageButton ibLike;
public TestHolder(#NonNull View itemView) {
super(itemView);
tvPost = itemView.findViewById(R.id.tvPost);
tvLikes = itemView.findViewById(R.id.tvLikes);
ibLike = itemView.findViewById(R.id.ibLike);
}
}
Here need to initialize your adapter class from main activity. and then when data received just call adapter.notifiyDatasetChanged like:
onCreate():
postList = new ArrayList<>();
recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
testAdapter = new TestAdapter(getApplicationContext(), postList);
recyclerView.setAdapter(testAdapter);
and from your fetchPostFromDB delete adapter initialization insted of this just put this line testAdapter.notifiyDataSetChanged()
And when click on text button you can update/handle like this:
holder.ibLike.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String postID = postList.get(holder.getAdapterPosition()).getPostID();
databaseReference = FirebaseDatabase.getInstance().getReference("Posts").child(postID).child("likes");
int incrementLike = postList.get(holder.getAdapterPosition()).getLikes() + 1;
postList.get(holder.getAdapterPosition()).setLikes(incrementLike);
databaseReference.setValue(incrementLike);
notifyDataSetChanged();
}
});
i am trying to pass holders user.getID to my attendance activity how can i pass users id from my adapter to attendance activity
this is my attendance activity
reference = FirebaseDatabase.getInstance().getReference("parent");
intent = getIntent();
final String currentSubject = intent.getStringExtra("currentSubject");
reference.addValueEventListener(new ValueEventListener() {
#RequiresApi(api = Build.VERSION_CODES.O)
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
final User user = snapshot.getValue(User.class);
ZoneId zonedId = ZoneId.of("America/Montreal");
final LocalDate today = LocalDate.now(zonedId);
reference = FirebaseDatabase.getInstance().getReference("attendance").child(user.getSchoolcode()).child(grade.getText().toString() + " " + section.getText().toString()).child(currentSubject).child(today.toString()).child(userID);
reference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("attendance", "yes");
reference.updateChildren(hashMap);
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
}
i want to pass it from adapter to this
this is my adapter
public class StudentAdapter extends RecyclerView.Adapter<StudentAdapter.ViewHolder> {
private Context context;
private List<User> users;
public StudentAdapter(Context context, List<User> users) {
this.context = context;
this.users = users;
}
DatabaseReference reference;
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.student_item, parent, false);
return new StudentAdapter.ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull final ViewHolder holder, int position) {
final User user = users.get(position);
holder.studentName.setText(user.getStudentname() + " " + user.getLastname());
}
#Override
public int getItemCount() {
return users.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView studentName;
public Switch aSwitch;
public ViewHolder(View itemView) {
super(itemView);
studentName = itemView.findViewById(R.id.studentName);
aSwitch = itemView.findViewById(R.id.attendanceSwitch);
}
}
this is my adapter which holds the recyclerview,i am trying to get id of users viewed on attendance activities recyclerview
A way that you can use is callback :
In your adapter define an interface like this :
public class StudentAdapter extends RecyclerView.Adapter<StudentAdapter.ViewHolder> {
private SendCallBack mCallback;
interface SendCallBack {
void send(int id);
}
//Initial callback in constructor
public StudentAdapter(Context context, List<User> users,SendCallBack callback) {
this.context = context;
this.users = users;
mCallback = callback;
}
//Now in where that you want to pass data use this
mCallback.send(user.getID);
}
Now in your activity implement the callback like this :
public class YourActivty implements YourAdapter.SendCallback {
#Override
public void send(int id) {
}
//For pass callBack for your adapter constructor use this
}
For other ways you can use this link.