Skip to main content

Posts

Showing posts with the label togglebutton

NullPointerException - What to do?

I'm experiencing a NullpointerException with this code: kuglebutton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if(toggle.isChecked()) { counter1 = counter1 + 10; column1tv.setText("" + counter1); } else { counter1 = counter1 - 2; column1tv.setText("" + counter1); } } }); Can anyone tell me what i'm doing wrong, and maybe how to fix it?

<ToggleButton> onClickListener - changing drawable back to default

I've got this ToggleButton which is supposed to change the drawables (and functions) of some other buttons upon toggling on/off. So far i've only managed to make it work one way, by using this code. @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); toggle = (ToggleButton) findViewById(R.id.bRedGreen); toggle.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub minuskugle = (Button) findViewById(R.id.bBallhole); minuskugle.setBackgroundResource(R.drawable.redballinhole); } }); } How do you make it change the drawable back to default upon another click? _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __