Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old July 13th, 2009, 03:43 PM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jul 2009
Posts: 2
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default If statement problem?

Hey there,
I'm really confused right now as to why this isn't working.
What I am trying to achieve is to allow the user to select either the Light theme or the Dark theme. Now I have got that bit sorted (Storing it in preferences). The problem is coming to applying the theme. I'm trying to apply the theme before the super.onCreate() method in the onCreate method.

Code:
public static String mSettingTheme;

protected void onCreate(Bundle savedInstanceState) 
 {
 /* THEME LOGIC BEFORE SUPER.ONCREATE*/
 // Load the settings from Disk and set anythign up we need to before drawing.

mSettingTheme = loadSettings();
if( mSettingTheme == "Light" )
{
   setTheme(android.R.style.Theme_Light);
}
else if (mSettingTheme == "Dark")
{
    setTheme(android.R.style.Theme_Black);
}
 
super.onCreate(savedInstanceState);
 // Load view    
 setContentView(R.layout.settings);
The loadSettings() method is returning a string with the name of the theme to load ("Light" or "Dark"). However neither of the if conditions are met and it fails to load either and I cannot understand why.

Thanks in advance for any help

SystemBomber is offline  
Last edited by SystemBomber; July 13th, 2009 at 03:44 PM.
Reply With Quote
sponsored links
Old July 13th, 2009, 04:05 PM   #2 (permalink)
Senior Member
 
KlaymenDK's Avatar
 
Join Date: May 2009
Location: Denmark
Posts: 1,221
 
Device(s): HTC Desire Z (rooted, CyanogenMod v7.1; Revoked ClockworkMod) HTC Desire (rooted, Oxygen rom; Revoke
Carrier: Not Provided

Thanks: 31
Thanked 132 Times in 100 Posts
Default

Object Oriented Programming 101: Your class must call super as the #1 thing.

Having said that, why is it important to you to run that statement prior to super? Have you tried to run it between the super and your setContentView() ?
__________________
Don't forget to hit the "Thanks" button when someone helps you!!!
How To Ask Questions The Smart Way
-- 010\001\111 --
KlaymenDK is offline  
Last edited by KlaymenDK; July 13th, 2009 at 04:05 PM. Reason: typo >_<
Reply With Quote
Old July 13th, 2009, 04:07 PM   #3 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jul 2009
Posts: 2
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well when setting a theme, it seems to only work before super. Which is a pain in the butt really. Does not work between super and setContentView.
SystemBomber is offline  
Reply With Quote
Old July 14th, 2009, 02:43 AM   #4 (permalink)
Senior Member
 
KlaymenDK's Avatar
 
Join Date: May 2009
Location: Denmark
Posts: 1,221
 
Device(s): HTC Desire Z (rooted, CyanogenMod v7.1; Revoked ClockworkMod) HTC Desire (rooted, Oxygen rom; Revoke
Carrier: Not Provided

Thanks: 31
Thanked 132 Times in 100 Posts
Default

Well, according to the canonical example it's supposed to work like this:
Code:
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...
    setTheme(android.R.style.Theme_Light);
    setContentView(R.layout.linear_layout_3);
}
Maybe there's a bug in your theme XML?
KlaymenDK is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 11:25 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.