I implement a Toggle Botton on Activity. I wanted to add Sound (on & off) to that button but I am not able to add sound on it.
This is the code I wrote.
public class SoundLayout extends Activity implements OnClickListener
{
Button soundBttnOn;
private String _showText;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.sound_layout);
/** Fetched from the MAIN ACTIVITY */
Bundle bundle = getIntent().getExtras();
if(bundle!=null){
_showText = bundle.getString("button_click");
}
Log.i("btnClick","button clicked is :"+_showText);
soundBttnOn = (Button) findViewById(R.id.togglebutton);
soundBttnOn.setOnClickListener(this);
}
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
/** make a refernce to store the intent when the view has been clicked*/
Intent intent;
/** Make cases according to the number of buttons you have in screen
* In this case, I've added one.*/
switch(view.getId()){
case R.id.togglebutton :
Log.i("btnClick","Result button is clicked whose id is :"+view.getId());
/** Intent should be fired from this activity to the other activity*/
intent = new Intent(SoundLayout.this, Main.class);
/** Start the intent
* startActivity(intent);
this.finish();*/
break;
}
}
}
Here I tried to add Sound on toggle button, but I am not able to add sound function on it. So when I click on 'sound on', it gets activated and when I click on 'sound off', it gets deactivated.