Android Studio:如何根据用户单击的位置创建特定的警报对话框
我是Android Studio编程的新手。我的程序有一个带有3个文本视图的Recyclerview和一个图像。我希望根据用户在屏幕上单击的位置出现一个警报对话框,例如,如果用户单击对话框的图像,则“您单击了图像”。如果用户单击文本,则会说“您单击文本”。 我的单击听众如下:itemview.setOnClickListener(this);
@Override
public void onClick(View view) {
int index = getAdapterPosition();
if (playerNames.equals(index)) {
showDialogPlayerNames();
}
if (numberPlayers.equals(index)){
showDialogPlayerNumber();
}
if (ScorePlayers.equals(index)){
showDialogPlayerScore();
}
if (picturePlayers.equals(index)) {
showDialogPlayerImage();
}
}
}
这是我的警报对话框代码:
void showDialogPlayerNames() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
alertDialog.setTitle("Click Information");
alertDialog.setIcon(R.drawable.ic_baseline_info_24);
alertDialog.setMessage("You clicked Player Name");
alertDialog.setNegativeButton("Dismiss", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
alertDialog.create().show();
}
谢谢
I am new to Android Studio programming. My program has a recyclerview with 3 Textviews, and one image. I would like an alert dialog to appear based on where the user clicks on the screen, for instance if the user clicks on the image the dialog says, "You clicked on image". If the user clicks on the text, it would say "You clicked on the text".
My onclick listener is as follows: itemView.setOnClickListener(this);
@Override
public void onClick(View view) {
int index = getAdapterPosition();
if (playerNames.equals(index)) {
showDialogPlayerNames();
}
if (numberPlayers.equals(index)){
showDialogPlayerNumber();
}
if (ScorePlayers.equals(index)){
showDialogPlayerScore();
}
if (picturePlayers.equals(index)) {
showDialogPlayerImage();
}
}
}
Here is my alert dialog code:
void showDialogPlayerNames() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
alertDialog.setTitle("Click Information");
alertDialog.setIcon(R.drawable.ic_baseline_info_24);
alertDialog.setMessage("You clicked Player Name");
alertDialog.setNegativeButton("Dismiss", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
alertDialog.create().show();
}
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在方法中添加参数
You need to add parameters in your methods