android - Different themes are required by activity and fragment for dialog box -


i trying create dialog box fragment(mainscreenfragment.java). there many fragments called mainactivity since using tab view here using holo theme mainactivity when try create alert box, error shows in fragment saying " java.lang.illegalstateexception: need use theme.appcompat theme (or descendant) activity."

please tell me do!

manifest.xml

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.example.coderahul.player">      <uses-permission android:name="android.permission.internet" />     <uses-permission android:name="android.permission.read_external_storage" />     <uses-permission android:name="android.permission.write_external_storage" />      <application         android:allowbackup="true"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"         android:supportsrtl="true"         android:theme="@style/apptheme">         <activity             android:name=".mainactivity"             android:label="@string/app_name"             android:theme="@android:style/theme.holo">             <intent-filter>                 <action android:name="android.intent.action.main" />                  <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>         <activity android:name=".songplay">             <intent-filter>                 <action android:name="android.intent.action.main" />             </intent-filter>         </activity>          <service             android:name=".musicservice"             android:enabled="true" />          <activity             android:name=".mainscreen"             android:label="@string/title_activity_main_screen"             android:theme="@style/apptheme.noactionbar" />         <activity             android:name=".playlistscreen"             android:label="@string/title_activity_playlist_screen"             android:theme="@style/apptheme.noactionbar" />         <activity             android:name=".playlistmanager"             android:label="@string/title_activity_playlist_manager"             android:theme="@style/apptheme.noactionbar" />         <activity             android:name=".genrescreen"             android:label="@string/title_activity_genre_screen"             android:theme="@style/apptheme.noactionbar" />         <activity             android:name=".genrelistmanager"             android:label="@string/title_activity_genrelist_manager"             android:theme="@style/apptheme.noactionbar" />         <activity             android:name=".albumscreen"             android:label="@string/title_activity_album_screen"             android:theme="@style/apptheme.noactionbar" />         <activity             android:name=".albumscreenmanager"             android:label="@string/title_activity_album_screen_manager"             android:theme="@style/apptheme.noactionbar" />         <activity             android:name=".artistscreen"             android:label="@string/title_activity_artist_screen"             android:theme="@style/apptheme.noactionbar" />         <activity             android:name=".artistmanager"             android:label="@string/title_activity_artist_manager"             android:theme="@style/apptheme.noactionbar"></activity>     </application>  </manifest> 

styles.xml

<resources>      <!-- base application theme. -->     <style name="apptheme" parent="theme.appcompat.light.darkactionbar">         <!-- customize theme here. -->         <item name="colorprimary">@color/colorprimary</item>         <item name="colorprimarydark">@color/colorprimarydark</item>         <item name="coloraccent">@color/coloraccent</item>     </style>      <style name="apptheme.noactionbar">         <item name="windowactionbar">false</item>         <item name="windownotitle">true</item>     </style>      <style name="apptheme.appbaroverlay" parent="themeoverlay.appcompat.dark.actionbar" />      <style name="apptheme.popupoverlay" parent="themeoverlay.appcompat.light" />      <style name="mydialogtheme" parent="theme.appcompat" />  </resources> 

mainactivity.java

public class mainactivity extends fragmentactivity implements actionbar.tablistener {  int check=0; private viewpager viewpager; private tabviewadapter tabpageradapter; private actionbar actionbar; private string[] tabnames = { "genres", "playlists", "all songs", "albums", "artists" };   @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     viewpager = (viewpager) findviewbyid(r.id.viewpager);     tabpageradapter = new tabviewadapter(getsupportfragmentmanager());     viewpager.setadapter(tabpageradapter);     viewpager.setoffscreenpagelimit(5);     actionbar = getactionbar();     actionbar.sethomebuttonenabled(true);     actionbar.setnavigationmode(actionbar.navigation_mode_tabs);     (int = 0; < 5 ; i++) {         actionbar.addtab(actionbar.newtab().settext(tabnames[i])                 .settablistener(this));     }     viewpager.setcurrentitem(2);     actionbar.setselectednavigationitem(2);     viewpager.setonpagechangelistener(new onpagechangelistener() {         @override         public void onpageselected(int postion) {             check = postion;             actionbar.setselectednavigationitem(postion);         }         @override         public void onpagescrolled(int arg0, float arg1, int arg2) {         }         @override         public void onpagescrollstatechanged(int arg0) {         }     }); }  @override public void ontabreselected(tab tab, fragmenttransaction ft) { }  @override public void ontabselected(tab tab, fragmenttransaction ft) {     viewpager.setcurrentitem(tab.getposition()); }  @override public void ontabunselected(tab tab, fragmenttransaction ft) { }  @override public void onbackpressed() {     if((mainscreenfragment.menu).getvisibility()==view.visible)         (mainscreenfragment.menu).setvisibility(view.invisible);     else         movetasktoback(true); } } 

mainscreenfragment.java

private view.onclicklistener menubutton = new view.onclicklistener() {      @override     public void onclick(view v) {         log.v("checkmenu", "working!!");          switch (v.getid()) {             case r.id.add: {                 log.v("checkmenuadd", "working!!");                  final sqlitedatabase mydatabase = getactivity().openorcreatedatabase("beats_playlists", android.content.context.mode_private, null);                 mydatabase.execsql("create table if not exists playlists(playlistname varchar primary key);");                  list<string> playlists = new arraylist<string>();                 cursor cursor = mydatabase.rawquery("select * playlists", null);                 playlists.add("create new");                 if(cursor.movetofirst()) {                     while(cursor.isafterlast()==false) {                         string name = cursor.getstring(cursor                                 .getcolumnindex("playlistname"));                          playlists.add(name);                         cursor.movetonext();                     }                 }                 cursor.close();                  final charsequence[] playlistsdata = playlists.toarray(new string[playlists.size()]);                 final alertdialog.builder dialogbuilder = new alertdialog.builder(getactivity(), r.style.mydialogtheme);                 dialogbuilder.settitle("add playlist");                 dialogbuilder.setitems(playlistsdata, new dialoginterface.onclicklistener() {                     public void onclick(dialoginterface dialog, int item) {                         string selectedtext = playlistsdata[item].tostring();                          if(selectedtext.equals("create new")){                             final string[] playlistname = {""};                             alertdialog.builder alertdialog = new alertdialog.builder(getactivity());                             alertdialog.settitle("create new");                              final edittext input = new edittext(getactivity());                             linearlayout.layoutparams lp = new linearlayout.layoutparams(                                     linearlayout.layoutparams.match_parent,                                     linearlayout.layoutparams.match_parent);                             input.setlayoutparams(lp);                             alertdialog.setview(input);                              alertdialog.setpositivebutton("create",                                     new dialoginterface.onclicklistener() {                                         public void onclick(dialoginterface dialog, int which) {                                             playlistname[0] = input.gettext().tostring();                                             if(!playlistname[0].equals("")) {                                                 try {                                                     mydatabase.execsql("insert playlists values(\'" + playlistname[0].trim() + "\');");                                                     mydatabase.execsql("create table " + playlistname[0].trim() + "(songpath varchar primary key)");                                                     mydatabase.execsql("insert " + playlistname[0].trim() + " values(\'" + songpath + "\');");                                                 }                                                 catch (exception e) {                                                     toast.maketext(getactivity(),                                                             "playlist exist", toast.length_short).show();                                                 }                                             }                                         }                                     });                              alertdialog.setnegativebutton("cancel",                                     new dialoginterface.onclicklistener() {                                         public void onclick(dialoginterface dialog, int which) {                                             dialog.cancel();                                         }                                     });                              alertdialog.show();                         }                          else {                             try {                                 mydatabase.execsql("insert " + selectedtext + " values(\'" + songpath + "\');");                             }                             catch (exception e){                                 toast.maketext(getactivity(),                                         "track exists in playlist", toast.length_short).show();                             }                         }                     }                 });                   alertdialog alertdialogobject = dialogbuilder.create();                 alertdialogobject.show();                 window window = alertdialogobject.getwindow();                 window.setlayout(actionbar.layoutparams.match_parent, 300);                  break;             }         }     } }; 


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -