Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4362: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4364: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4365: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4366: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
anddev.org • View topic - how to get the id for the background of a button?

how to get the id for the background of a button?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

how to get the id for the background of a button?

Postby srajpal » Mon Jan 26, 2009 10:21 pm

I created a button like so

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Button b;
  3.  
  4. b.setBackgroundResource(R.drawable.bg_img);
  5.  
  6.  
Parsed in 0.010 seconds, using GeSHi 1.0.8.4



does anybody know how the get the id for the image back out of the button?

I tried

b.getBackground();
and
b.getResources();

but i cannot figure out how to get to the id to see what image is set as the background of the button.
--
Sunny
srajpal
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Jan 09, 2009 7:48 pm

Top

Postby MrSnowflake » Mon Jan 26, 2009 10:26 pm

You probably can't because not every button has a background resource. But you can get the drawable...
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby srajpal » Mon Jan 26, 2009 10:45 pm

how would i compare that to images i have to see which image was on the button?
i have 6 buttons with images and i need to know which button has which image as the images will change on the buttons as they are clicked.
--
Sunny
srajpal
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Jan 09, 2009 7:48 pm

Postby Quetzalcoatl » Wed Jan 28, 2009 3:14 pm

Easiest way would be to store the state of the button somewhere within the class. You could have something like

int mButtonState = null;

b.setBackgroundResource(R.drawable.bg_img);
mButtonState = R.drawable.bg_img;

So that you always know what your button has been set to rather than analysing the button directly. :wink:
Image
Quetzalcoatl
Senior Developer
Senior Developer
 
Posts: 129
Joined: Sat Oct 18, 2008 8:21 pm
Location: near Manchester, UK

Postby srajpal » Wed Jan 28, 2009 4:56 pm

that is the way i did it but i thought it was extraneous, i wanted to simplify the programming
thank you for your help
--
Sunny
srajpal
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Jan 09, 2009 7:48 pm

Postby MrSnowflake » Thu Jan 29, 2009 10:01 am

Quetzalcoatl wrote:int mButtonState = null;
This won't work, int is not a reference type :).
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Postby Quetzalcoatl » Thu Jan 29, 2009 10:20 am

:oops: :D

int mButtonState = 0;

Which I suppose isn't necessary as Java does it for you I believe :shock:
Image
Quetzalcoatl
Senior Developer
Senior Developer
 
Posts: 129
Joined: Sat Oct 18, 2008 8:21 pm
Location: near Manchester, UK

Postby MrSnowflake » Thu Jan 29, 2009 10:24 am

Well it is supposed to :).
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby darolla » Fri Jan 30, 2009 2:34 pm

isnt it easier to use xml for that buttons instead of java?

u need that <selector> stuff...

viewtopic.php?p=17050

http://www.androidianer.de/eigene-buttons-definieren

tinytutcustom_button_backgrounds-better_imagebutton-t4298.html

greetings,
darolla
User avatar
darolla
Master Developer
Master Developer
 
Posts: 273
Joined: Thu Sep 25, 2008 5:16 pm
Location: Dortmund, Germany

Postby srajpal » Sun Feb 01, 2009 4:07 am

wow those are some excellent tutorials, i will definitely do it this way when i am designing my own buttons

i was makings a button that will take one of 8 colors so i am not able to do it that way

my final app looks like this, each of the circles is a button

coming soon to the market place ;)

Image
--
Sunny
srajpal
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Jan 09, 2009 7:48 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 7 guests