Reputation: 3
I was following a Youtube tutorial to show alert Dialog Box on my View Holder.In order to send the user to a Specific Activity based on their selection.But when I click on the View Holder it is not even showing up or doing anything.However the Onclick Listener is working fine.I have tried it with a Toast message and the Toast is showing.
private RecyclerView myFriendsList;
private DatabaseReference FriendsRef,UsersRef;
private FirebaseAuth mAuth;
private String online_user_id;
private TextView friends;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_friends);
myFriendsList = (RecyclerView) findViewById(R.id.friends_list);
friends = (TextView) findViewById(R.id.all_friends);
myFriendsList.setHasFixedSize(true);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setReverseLayout(true);
linearLayoutManager.setStackFromEnd(true);
myFriendsList.setLayoutManager(linearLayoutManager);
mAuth = FirebaseAuth.getInstance();
online_user_id = mAuth.getCurrentUser().getUid();
FriendsRef = FirebaseDatabase.getInstance().getReference().child("Friends").child(online_user_id);
UsersRef = FirebaseDatabase.getInstance().getReference().child("Users");
DisplayAllFriends();
}
private void DisplayAllFriends() {
FirebaseRecyclerOptions<Friends> options=new FirebaseRecyclerOptions.Builder<Friends>().
setQuery(FriendsRef ,Friends.class).build();
FirebaseRecyclerAdapter<Friends, FriendsViewHolder> adapter = new FirebaseRecyclerAdapter<Friends, FriendsViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull final FriendsViewHolder holder,int position, @NonNull Friends model) {
holder.setDate(model.getDate());
final String userIDs = getRef(position).getKey();
UsersRef.child(userIDs).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists())
{
final String username = dataSnapshot.child("fullname").getValue().toString();
final String profileimage = dataSnapshot.child("profileimage").getValue().toString();
holder.setFullname(username);
holder.setProfileimage(getApplicationContext(),profileimage);
holder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CharSequence options[] = new CharSequence[]
{
username + "'s Profile",
"Send Message"
};
AlertDialog.Builder builder = new
AlertDialog.Builder(FriendsActivity.this);
builder.setTitle("Select Options");
builder.setItems(options, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(which == 0)
{
Intent ProfileIntent = new
Intent(FriendsActivity.this,PersonProfileActivity.class);
ProfileIntent.putExtra("visit_user_id",userIDs);
startActivity(ProfileIntent);
}
if(which == 1)
{
Intent ChatIntent = new
Intent(FriendsActivity.this,ChatActivity.class);
ChatIntent.putExtra("visit_user_id",userIDs);
startActivity(ChatIntent);
}
}
});
}
});
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
@NonNull
@Override
public FriendsViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view= LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.all_users_display_layout,viewGroup,false);
FriendsActivity.FriendsViewHolder holder=new FriendsActivity.FriendsViewHolder(view);
return holder;
}
};
myFriendsList.setAdapter(adapter);
adapter.startListening();
}
public static class FriendsViewHolder extends RecyclerView.ViewHolder
{
View mView;
public FriendsViewHolder(@NonNull View itemView) {
super(itemView);
mView = itemView;
}
public void setProfileimage(Context ctx, String profileimage) {
CircleImageView myImage = (CircleImageView) mView.findViewById(R.id.all_users_profile_image);
PicassoProvider.get().load(profileimage).placeholder(R.drawable.profile).into(myImage);
}
public void setFullname(String fullname) {
TextView myName = (TextView) mView.findViewById(R.id.all_users_profile_full_name);
myName.setText(fullname);
}
public void setDate(String date) {
TextView friendsDate = (TextView) mView.findViewById(R.id.all_users_status);
friendsDate.setText("Friends Since: " + date);
}
}
Upvotes: 0
Views: 156
Reputation: 13
builder.show(); would let the dialog appear when the method is run.
Upvotes: 0
Reputation: 2283
You forgot to call builder.show()
in your alert dialog builder. You can call this method after builder.setItems(...)
Upvotes: 1