Help me to build checkboxes in android

Diah Permatasari

New member
May 13, 2013
0
0
0
I have two checkboxes . pencil and book. And I have 1 textview to total:


package apa.y;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;


public class myprice extends Activity {
/** Called when the activity is first created. */


CheckBox book,pencil;
TextView total;
int sum=0;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.mymain);
pencil = (CheckBox) findViewById(R.id.pencil);
book = (CheckBox) findViewById(R.id.book);
total = (TextView) findViewById(R.id.total);

}

public void onClick(View v) {

sum = 0;
if (pencil.isChecked()) {sum += 10;}else{sum +=0;}
if (book.isChecked()) sum += 5;else{sum +=0;}

total.setText("Total: "+sum);

} }



but didnt work. . Help me peaseee
 

Latest posts

Trending Posts

Forum statistics

Threads
963,381
Messages
6,993,184
Members
3,165,018
Latest member
Taylor Bag