简体   繁体   中英

Android: package android.support.v7.app.AlertDialog does not exist

So im trying to implement a barcode scanner functionallity And i have this piece of code

 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();
    }

and i get this error error: package android.support.v7.app.AlertDialog does not exist new android.support.v7.app.AlertDialog.Builder(addquantityactivity.this)

To mention, i use androidx and i have tried the following imports..Also other solutions on stackoverflow didnt helped me.

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

Try this code. I hope this will work. If AlertDialog not imported then re-import the androidx version.

private void showMessageOKCancel(String message, DialogInterface.OnClickListener okListener) {
        new AlertDialog.Builder(addquantityactivity.this)
                .setMessage(message)
                .setPositiveButton("OK", okListener)
                .setNegativeButton("Cancel", null)
                .create()
                .show();
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM