1. Download our Official Android App: Forums for Android!

Apps ImageButton, onkeydown and picture?

Discussion in 'Android Development' started by Grendizer, Mar 6, 2011.

  1. Grendizer

    Grendizer Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    10
    Joined:
    Mar 14, 2010

    Mar 14, 2010
    10
    0
    15
    Hi all,

    I have a Dialpad in which there are multiple buttons. Whenever a button is clicked a sounds plays and the background of the imagebutton is changed.
    For this I'm using
    PHP:
    1. ImageButton zero = (ImageButton) findViewById(R.id.btnZero);
    2.         zero.setOnClickListener(new OnClickListener() {
    3.             public void onClick(View v) {
    4.                 playSound(R.raw.mamacita_zero);
    5.             }
    6.         });
    And the XML for the button is as follows:
    PHP:
    1. <?xml version="1.0" encoding="utf-8"?>
    2.  <selector xmlns:android="http://schemas.android.com/apk/res/android">
    3.  
    4.      <item
    5.          android:state_pressed="true"        
    6.         android:drawable="@drawable/green0" /> <!-- pressed -->        
    7.        
    8.      <item
    9.          android:drawable="@drawable/blue0" /> <!-- default -->
    10.      
    11.  </selector>
    I also have an onKeyDown(...) method for playing the sound, but I'm not able to get the imagebutton to switch background on the click...So my question is how to change the imagebutton's background when the onkeydown method is used?
    Any tips would be appreciated...
     

    Advertisement

  2. antonykk

    antonykk Lurker
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Mar 1, 2011

    Mar 1, 2011
    3
    0
    5

Share This Page

Loading...