java - Alert Dialog not displaying due to IllegalStateException -
when click on listview row, instead of showing alert dialog box, gives illegalstateexception. says use theme.appcompat theme. dont know , new plese me understand these appcompat activity , reason trouble.
java.lang.illegalstateexception: need use theme.appcompat theme (or descendant) activity. @ android.support.v7.app.appcompatdelegateimplv9.createsubdecor(appcompatdelegateimplv9.java:355) @ android.support.v7.app.appcompatdelegateimplv9.ensuresubdecor(appcompatdelegateimplv9.java:324) @ android.support.v7.app.appcompatdelegateimplv9.setcontentview(appcompatdelegateimplv9.java:285) @ android.support.v7.app.appcompatdialog.setcontentview(appcompatdialog.java:83) @ android.support.v7.app.alertcontroller.installcontent(alertcontroller.java:225) @ android.support.v7.app.alertdialog.oncreate(alertdialog.java:257) @ android.app.dialog.dispatchoncreate(dialog.java:397) @ android.app.dialog.show(dialog.java:298) @ com.example.stark.messenger.showdatabase$1.onitemclick(showdatabase.java:93) @ android.widget.adapterview.performitemclick(adapterview.java:310) @ android.widget.abslistview.performitemclick(abslistview.java:1145) @ android.widget.abslistview$performclick.run(abslistview.java:3081) @ android.widget.abslistview$3.run(abslistview.java:3947) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:148) @ android.app.activitythread.main(activitythread.java:5441) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:738) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:628)
the code main activity is:
import android.content.dialoginterface; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqliteopenhelper; import android.os.bundle; import android.support.v7.app.appcompatactivity; import android.view.view; import android.widget.adapterview; import android.widget.listview; import java.util.arraylist; public class showdatabase extends appcompatactivity { sqliteopenhelper expensedatabase; sqlitedatabase db; cursor cursor; listview lv; arraylist<datamodel> datamodels; private static customadapter adapter; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_show_database); lv=(listview) findviewbyid(r.id.lv_custom_list); expensedatabase = new expensedatabase(this); db = expensedatabase.getreadabledatabase(); } protected void onstart() { super.onstart(); datamodels = new arraylist<datamodel>(); datamodels.clear(); cursor = db.rawquery("select * expenserecord strftime('%y-%m', date) = '2017-04';",null); if (cursor != null && cursor.getcount() != 0) { if (cursor.movetofirst()) { { datamodel datamodelitems = new datamodel(); datamodelitems.setpayee(cursor.getstring(cursor .getcolumnindex("payee"))); datamodelitems.setamount(cursor.getstring(cursor .getcolumnindex("amount"))); datamodelitems.setcategory(cursor.getstring(cursor .getcolumnindex("category"))); datamodelitems.setnotes(cursor.getstring(cursor .getcolumnindex("notes"))); datamodelitems.setdate(cursor.getstring(cursor .getcolumnindex("date"))); datamodelitems.settime(cursor.getstring(cursor .getcolumnindex("time"))); datamodels.add(datamodelitems); } while (cursor.movetonext()); } } cursor.close(); customadapter customadapter = new customadapter(datamodels,getapplicationcontext()); lv.setadapter(customadapter); lv.setonitemclicklistener(itemlistener); } adapterview.onitemclicklistener itemlistener = new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { final android.support.v7.app.alertdialog.builder builder = new android.support.v7.app.alertdialog.builder(getapplicationcontext()); builder.setview(r.layout.dialog_box) .setpositivebutton("update", new dialoginterface.onclicklistener() { public void onclick(final dialoginterface dialog, final int id) { //update click } }) .setneutralbutton("disable", new dialoginterface.onclicklistener() { public void onclick(final dialoginterface dialog, final int id) { //disable click } }) .setnegativebutton("cancel", new dialoginterface.onclicklistener() { public void onclick(final dialoginterface dialog, final int id) { //cancel click } }); if(position>-1) { android.support.v7.app.alertdialog alert = builder.create(); alert.show(); } } }; public void ondestroy(){ super.ondestroy(); cursor.close(); db.close(); }
}
try adding
android:theme="@style/theme.appcompat.light"
to application tag in androidmanifest.xml file.
as suggested in post.
Comments
Post a Comment