gpt4 book ai didi

android - 如何在 recyclerview 中为每个 cardview 实现单选警报对话框?

转载 作者:行者123 更新时间:2023-11-29 18:29:00 25 4
gpt4 key购买 nike

我是 Android 开发新手。我正在构建一个在 recyclerview 中具有卡片 View 的应用程序。我想制作一个单选警报对话框列表并处理它们。我正在使用 FirebaseUI 库来填充 recyclerview。

这是我的 ViewHolder 类:

public class FriendListViewHolder extends RecyclerView.ViewHolder{

public CircleImageView friendPhoto;
public TextView friendName;
public CardView friendsCardView;

public FriendListViewHolder(@NonNull final View itemView) {
super(itemView);

friendPhoto = itemView.findViewById(R.id.friendProfilePhoto);
friendName = itemView.findViewById(R.id.friendNameText);
friendsCardView = itemView.findViewById(R.id.friends_cardview);

}

}

每当用户点击卡片 View 时,alerdialog 就会弹出。但请记住,我需要知道选择了哪个汽车 View 。

最佳答案

我正在尝试但未测试,概念是这样的,如果不适合您请告诉我

    public class FriendListViewHolder extends RecyclerView.ViewHolder{

public CircleImageView friendPhoto;
public TextView friendName;
public CardView friendsCardView;

public FriendListViewHolder(@NonNull final View itemView) {
super(itemView);

friendPhoto = itemView.findViewById(R.id.friendProfilePhoto);
friendName = itemView.findViewById(R.id.friendNameText);
friendsCardView = itemView.findViewById(R.id.friends_cardview);

friendsCardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

new AlertDialog.Builder(itemView.getContext())
.setTitle("Title of the alert dialog")
.setMessage("The body of the alert dialog")

// Specifying a listener allows you to take an action before dismissing the dialog.
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Continue with delete operation
}
})

// A null listener allows the button to dismiss the dialog and take no further action.
.setNegativeButton(android.R.string.no, null)
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}
});
}

}

尽管引用那些问题RecyclerView onClick , How do I display an alert dialog on Android?

关于android - 如何在 recyclerview 中为每个 cardview 实现单选警报对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57437140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com