1-) Android - CHECKBOX KULLANIMI
1-)
CheckBox chk;//OnCreate nin üstünde tanımla
chk= (CheckBox) findViewById(R.id.chk);
chk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Boolean durum=chk.isChecked();
}});
2-)-------2.yolda CheckBox-->properties-->OnClick-->tik yaz(tik adında metod oluştur)
CheckBox chk;//OnCreate nin üstünde tanımla
btn= (Button) findViewById(R.id.btn);//OnCreate nin içinde tanımla
chk= (CheckBox) findViewById(R.id.chk);//OnCreate nin içinde tanımla
public void tik(View v){//OnCreate'in Üstünde tanımla
switch (v.getId()){
case R.id.chk:
boolean durum=((CheckBox)v).isChecked();
if(durum){
btn.setText("True");
}else{
btn.setText("false"); }
break
;}}
1-)ilk önce string.xml in içine aşşağıdakini yapıştır
<resources>
<array name="renkler">
<item >mavi</item>
<item >turuncu</item>
<item >yeşil</item>
<item >kırmızı</item>
<item >sarı</item>
</array>
</resources>
2-)Spinner oluşturduğun yere gel yani activity_main.xml'e ve aşşağıdakini yapıştır.
<Spinner
android:id="@+id/spinner"
android:entries="@array/renkler"
/>
3-)Seçileni almak için MainActivity.java ya gel ve OnCreate'nin içine gel aşşağıdakini yapışştır
Spinner sp= (Spinner) findViewById(R.id.spinner);
final RelativeLayout zemin= (RelativeLayout) findViewById(R.id.rl);
sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
//position=index -->hangisini seçersen onun index'ini verir
switch (position){
case 0:
zemin.setBackgroundColor(Color.BLUE); break;
case 1:
zemin.setBackgroundColor(Color.YELLOW); break;
case 2:
zemin.setBackgroundColor(Color.GREEN); break;
case 3:
zemin.setBackgroundColor(Color.RED); break;
case 4:
zemin.setBackgroundColor(Color.WHITE); break; }} });