Here is a piece of code that will do what you want.
private static int myVariable = 100;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageButton btn = (ImageButton)findViewById
(R.id.ImageButton01);
btn.setOnClickListener(new OnClickListener(){
public void onClick(View v){
myVariable--;
audioAlert();
}
});
}
// There are different options to playing audioAlerts.
// I have posted one here. You may checkout
http://developer.android.com/guide/topics/media/index.html
// http://developer.android.com/reference/android/media/AudioManager.html
void audioAlert(){
AudioManager mAudioManager = (AudioManager)getSystemService
(Context.AUDIO_SERVICE);
int vol = mAudioManager.getStreamVolume
(AudioManager.STREAM_NOTIFICATION);
mAudioManager.setStreamVolume
(AudioManager.STREAM_NOTIFICATION, vol, 0);
mAudioManager.playSoundEffect(AudioManager.FX_KEY_CLICK, vol);
}
Hope this helps,
Balwinder Kaur
Open Source Development Center
·T· · ·Mobile· stick together
The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.
On Aug 10, 6:50 am, Hugh <[email protected]> wrote:
> Have some code loop repetitivly while an image button is held down?
> Specifically check a variable and then decrease a variable and play a
> sound.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---