<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<CheckBox
android:id="@+id/cbJava"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Java" />
<CheckBox
android:id="@+id/cbPhp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/cbJava"
android:layout_below="@+id/cbJava"
android:layout_marginTop="25dp"
android:text="Php" />
<Button
android:id="@+id/bHasil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/cbPhp"
android:layout_below="@+id/cbPhp"
android:layout_marginLeft="17dp"
android:layout_marginTop="82dp"
android:onClick="bHasilClick"
android:text="Hasil" />
<TextView
android:id="@+id/tvHasilradio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/cbJava"
android:layout_below="@+id/cbPhp"
android:layout_marginTop="27dp"
android:text="Pilih lalu klik Button"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
MainActivity.java
package
com.checkbox;
import
android.R.string;
import
android.os.Bundle;
import
android.app.Activity;
import
android.view.Menu;
import
android.view.View;
import
android.widget.CheckBox;
import
android.widget.RadioGroup;
import
android.widget.TextView;
public
class MainActivity extends Activity {
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu
menu) {
// Inflate the menu; this adds items to
the action bar if it is present.
getMenuInflater().inflate(R.menu.main,
menu);
return true;
}
public void bHasilClick(View v){
TextView
tvHasilradio = (TextView) findViewById(R.id.tvHasilradio);
CheckBox
cbJava = (CheckBox) findViewById(R.id.cbJava);
CheckBox
cbPhp = (CheckBox) findViewById(R.id.cbPhp);
String
s="";
if
(cbJava.isChecked()){
s
="Java";
}
if
(cbPhp.isChecked()){
s
= s + "PHP";
}
tvHasilradio.setText(s);
}
Tidak ada komentar:
Posting Komentar