java - Android:包 android.support.v7.app.AlertDialog 不存在
问题描述
所以我试图实现一个条形码扫描仪功能我有这段代码
private void showMessageOKCancel(String message, DialogInterface.OnClickListener okListener) {
new android.support.v7.app.AlertDialog.Builder(addquantityactivity.this)
.setMessage(message)
.setPositiveButton("OK", okListener)
.setNegativeButton("Cancel", null)
.create()
.show();
}
我得到这个错误error: package android.support.v7.app.AlertDialog does not exist new android.support.v7.app.AlertDialog.Builder(addquantityactivity.this)
值得一提的是,我使用 androidx 并且尝试了以下导入。stackoverflow 上的其他解决方案也没有帮助我。
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
解决方案
试试这个代码。我希望这会奏效。如果没有导入 AlertDialog 则重新导入androidx版本。
private void showMessageOKCancel(String message, DialogInterface.OnClickListener okListener) {
new AlertDialog.Builder(addquantityactivity.this)
.setMessage(message)
.setPositiveButton("OK", okListener)
.setNegativeButton("Cancel", null)
.create()
.show();
}
推荐阅读
- vba - Excel VBA:错误处理中断中间代码
- haskell - 哈斯克尔咖喱地图
- python - 将 C++ STL 容器传递给 Python?
- javascript - Javascript 自动填充选择
- python - 展平锯齿状 numpy 数组列表的列表
- python - 使用 array.contains() 对 postgresql 数组列进行查询过滤
- java - 可运行的 .jar 文件在我的 Windows 设备上运行,但不会在其他设备上运行(Windows 也是)
- python - 如何计算二维 python 列表中相似元素的总和?
- jenkins-pipeline - 节点故障时自动重新运行阶段
- javascript - Localstorage 在本地网页上不起作用:安全错误