android - Providing Option to change Themes Using Spinners -


i new java , android programming , hence, understanding not solid , hence, obliged if provided assistance here.

i want provide option allow end user change themes using spinner. however, when run app, fails on start up. mainactivity of app follows:

public class reminderlistactivity extends listactivity implements onitemclicklistener public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     utils.onactivitycreatesettheme(this); //for applying theme     setcontentview(r.layout.reminder_list);       spinner spin = (spinner) findviewbyid(r.id.spinner2);     arrayadapter<string> aa = new arrayadapter<string>(this,android.r.layout.simple_spinner_item,              themes);     spin.setadapter(aa);         spin.onitemclicklistener(this); //-->unable call onitemclick  method.    }  @override public void onitemclick(adapterview<?> parent, view view, int position, long arg3) {     // todo auto-generated method stub       switch(view.getid())     {      case 0:         utils.changetotheme(this, utils.theme_default);         break;      case 1:         utils.changetotheme(this, utils.theme_white);         break;      case 2:         utils.changetotheme(this, utils.theme_blue);         break;      default:          utils.changetotheme(this, utils.theme_white);         break;     } }            

the utils class follows:

private static int stheme;  public final static int theme_default = 0; public final static int theme_white = 1; public final static int theme_blue = 2;  /**  * set theme of activity, , restart creating new activity  * of same type.  */ public static void changetotheme(activity activity, int theme) {     stheme = theme;     activity.finish();      activity.startactivity(new intent(activity, activity.getclass())); }      /** set theme of activity, according configuration. */ public static void onactivitycreatesettheme(activity activity) {     switch (stheme)     {     default:     case theme_default:         break;     case theme_white:         activity.settheme(r.style.theme_white);         break;     case theme_blue:         activity.settheme(r.style.theme_blue);         break;     } } 

added initial problem:

i have changed onitemclicklistener onitemselectedlistener. application not crash when loads, screen keeps on blinking.

the code follows:

public class reminderlistactivity extends listactivity implements onitemselectedlistener { private static final int activity_create=0; private static final int activity_edit=1; private remindersdbadapter mdbhelper; string[] themes = { "default", "white", "blue"};    /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     utils.onactivitycreatesettheme(this); //for applying theme     setcontentview(r.layout.reminder_list);      mdbhelper = new remindersdbadapter(this);     mdbhelper.open();     filldata();     registerforcontextmenu(getlistview());      spinner spin = (spinner) findviewbyid(r.id.spinner2);     arrayadapter<string> aa = new arrayadapter<string>(this,android.r.layout.simple_spinner_item,              themes);     spin.setadapter(aa);         //spin.setonitemselectedlistener(this);//-->problem here unable call onitemclick method.                                        //what image adapter  }  @override public void onitemselected(adapterview<?> arg0, view arg1, int arg2,         long arg3) {     // todo auto-generated method stub       switch(arg1.getid())     {      case 0:         utils.changetotheme(this, utils.theme_default);         break;      case 1:         utils.changetotheme(this, utils.theme_white);         break;      case 2:         utils.changetotheme(this, utils.theme_blue);         break;      default:          utils.changetotheme(this, utils.theme_white);         break;     } }               @override public void onnothingselected(adapterview<?> arg0) {     // todo auto-generated method stub     utils.changetotheme(this, utils.theme_default);  } 

here logcat

05-10 09:12:56.449: e/trace(1004): error opening trace file: no such file or directory  (2) 05-10 09:12:59.369: d/dalvikvm(1004): gc_concurrent freed 180k, 11% free 2675k/2984k,  paused 86ms+10ms, total 242ms 05-10 09:12:59.369: d/dalvikvm(1004): wait_for_concurrent_gc blocked 61ms 05-10 09:12:59.403: i/dalvikvm-heap(1004): grow heap (frag case) 3.342mb 635812-byte allocation 05-10 09:12:59.529: d/dalvikvm(1004): gc_for_alloc freed 59k, 11% free 3236k/3608k, paused 120ms, total 121ms 05-10 09:12:59.609: d/dalvikvm(1004): gc_for_alloc freed <1k, 11% free 3236k/3608k, paused 57ms, total 58ms 05-10 09:12:59.622: i/dalvikvm-heap(1004): grow heap (frag case) 3.760mb 500416-byte allocation 05-10 09:12:59.779: d/dalvikvm(1004): gc_for_alloc freed <1k, 10% free 3724k/4100k, paused 152ms, total 152ms 05-10 09:13:00.039: d/dalvikvm(1004): gc_concurrent freed 1k, 10% free 3728k/4100k, paused 33ms+96ms, total 261ms 05-10 09:13:00.799: i/choreographer(1004): skipped 33 frames!  application may doing work on main thread. 05-10 09:13:00.889: d/gralloc_goldfish(1004): emulator without gpu emulation detected. 05-10 09:13:01.549: i/choreographer(1004): skipped 39 frames!  application may doing work on main thread. 05-10 09:13:03.999: d/dalvikvm(1004): gc_concurrent freed 770k, 22% free 3405k/4356k, paused 97ms+30ms, total 339ms 05-10 09:13:03.999: d/dalvikvm(1004): wait_for_concurrent_gc blocked 24ms 05-10 09:13:04.689: i/choreographer(1004): skipped 152 frames!  application may doing work on main thread. 05-10 09:13:05.899: i/choreographer(1004): skipped 68 frames!  application may doing work on main thread. 05-10 09:13:07.825: i/choreographer(1004): skipped 66 frames!  application may doing work on main thread. 05-10 09:13:10.030: i/choreographer(1004): skipped 70 frames!  application may doing work on main thread. 05-10 09:13:10.471: i/choreographer(1004): skipped 38 frames!  application may doing work on main thread. 05-10 09:13:11.510: i/choreographer(1004): skipped 32 frames!  application may doing work on main thread. 05-10 09:13:13.550: i/choreographer(1004): skipped 74 frames!  application may doing work on main thread. 05-10 09:13:14.040: i/choreographer(1004): skipped 37 frames!  application may doing work on main thread. 05-10 09:13:16.000: i/choreographer(1004): skipped 47 frames!  application may doing work on main thread. 05-10 09:13:16.530: i/choreographer(1004): skipped 50 frames!  application may doing work on main thread. 05-10 09:13:18.570: i/choreographer(1004): skipped 128 frames!  application may doing work on main thread. 05-10 09:13:20.809: d/dalvikvm(1004): gc_concurrent freed 151k, 16% free 3668k/4344k, paused 80ms+36ms, total 434ms 05-10 09:13:21.170: i/choreographer(1004): skipped 99 frames!  application may doing work on main thread. 05-10 09:13:22.959: i/choreographer(1004): skipped 82 frames!  application may doing work on main thread. 05-10 09:13:24.149: i/choreographer(1004): skipped 50 frames!  application may doing work on main thread. 05-10 09:13:24.679: i/choreographer(1004): skipped 48 frames!  application may doing work on main thread. 05-10 09:13:27.719: i/choreographer(1004): skipped 75 frames!  application may doing work on main thread. 05-10 09:13:29.279: i/choreographer(1004): skipped 45 frames!  application may doing work on main thread. 05-10 09:13:31.061: i/choreographer(1004): skipped 84 frames!  application may doing work on main thread. 05-10 09:13:31.449: i/choreographer(1004): skipped 31 frames!  application may doing work on main thread. 05-10 09:13:33.880: i/choreographer(1004): skipped 37 frames!  application may doing work on main thread. 05-10 09:13:34.249: i/choreographer(1004): skipped 30 frames!  application may doing work on main thread. 05-10 09:13:36.230: d/dalvikvm(1004): gc_concurrent freed 114k, 9% free 3939k/4308k, paused 47ms+69ms, total 832ms 05-10 09:13:37.539: i/choreographer(1004): skipped 75 frames!  application may doing work on main thread. 05-10 09:13:39.810: i/choreographer(1004): skipped 53 frames!  application may doing work on main thread. 05-10 09:13:40.970: i/choreographer(1004): skipped 41 frames!  application may doing work on main thread. 05-10 09:13:43.230: i/choreographer(1004): skipped 51 frames!  application may doing work on main thread. 05-10 09:13:43.672: i/choreographer(1004): skipped 39 frames!  application may doing work on main thread. 05-10 09:13:45.672: i/choreographer(1004): skipped 106 frames!  application may doing work on main thread. 05-10 09:13:47.770: i/choreographer(1004): skipped 87 frames!  application may doing work on main thread. 05-10 09:13:50.149: d/dalvikvm(1004): gc_concurrent freed 116k, 6% free 4226k/4472k, paused 79ms+50ms, total 544ms 

on changing listener onitemclicklistener onselecteditemlisteher. app not crash seems skipping frames. however, if onitemselectedlistener method not called, app functions properly.

the app loads "theme_white".

added existing question:

the whole oncreate() method shown below:

@override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     utils.onactivitycreatesettheme(this); //for applying theme     setcontentview(r.layout.reminder_list);      mdbhelper = new remindersdbadapter(this);     mdbhelper.open();     filldata();     registerforcontextmenu(getlistview());      spinner spin = (spinner) findviewbyid(r.id.spinner2);     arrayadapter<string> aa = new arrayadapter<string>(this,android.r.layout.simple_spinner_item,              themes);     spin.setadapter(aa);         spin.setonitemselectedlistener(this);  }  

spinner uses onitemselected not onitemclick(). change

spin.setonitemclicklistener(this) 

to

spin.setonitemselectedlistener(this); 

then change

public class reminderlistactivity extends listactivity implements onitemclicklistener 

to

public class reminderlistactivity extends listactivity implements onitemselectedlistener 

this why onitemclick() isn't getting called don't think should make program crash. so, may not answer current issue answer next question have. please post logcat can determine root of current problem.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -