gpt4 book ai didi

android - 点击并按住 - 怎么做?

转载 作者:行者123 更新时间:2023-11-30 00:09:04 28 4
gpt4 key购买 nike

我目前正在研究我在大学的期末项目,它看起来像 instagram。在 instagram android 应用程序中,您可以点击并按住图像和 boom,显示弹出窗口。但我不知道该怎么做!

最佳答案

您可以使用下面的代码来执行此类操作:

ImageView imageView = (ImageView ) findViewById(R.id.imageView2 );
imageView .isClickable();

imageView .setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "Clicked", Toast.LENGTH_SHORT).show();
// Here we can use to full view of image.
}
});

imageView .setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "Long Clicked", Toast.LENGTH_SHORT).show();
// Here we can use to show dialog.
showDialog();
return true;
}
});

在同一个 Activity 上创建弹出窗口/对话框:

 public void showDialog(){


AlertDialog.Builder builder = new AlertDialog.Builder(this);
//Uncomment the below code to Set the message and title from the strings.xml file
//builder.setMessage(R.string.dialog_message) .setTitle(R.string.dialog_title);

//Setting message manually and performing action on button click
builder.setMessage("Do you want to Like")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'NO' Button
dialog.cancel();
}
});

//Creating dialog box
AlertDialog alert = builder.create();
//Setting the title manually
alert.setTitle("AlertDialogExample");
alert.show();

}

关于android - 点击并按住 - 怎么做?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48486532/

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