Skip to content

Instantly share code, notes, and snippets.

@Bregnet
Created June 1, 2017 13:54
package custom.checkbox.example;
import android.content.*;
import android.util.*;
import android.view.*;
import android.widget.*;
public class MyCheckBox extends CheckBox implements CompoundButton.OnCheckedChangeListener
{
// iki kode ben checkbox dadi kode packagemu dewe
public MyCheckBox(Context c)
{
super(c);
CheckBoxKu();
}
public MyCheckBox(Context c, AttributeSet attr)
{
super(c, attr);
CheckBoxKu();
}
// checkboxku ganti sak senengmu
public void CheckBoxKu()
{
// gawe variable
CheckBox check = (CheckBox)findViewById(setResource("test_checkbox", "id"));
check.setOnCheckedChangeListener(this);
}
@Override
public void onCheckedChanged(CompoundButton button, boolean isChecked)
{
// iki ben ilang pas di check
if(isChecked)
{
setHide(4);
}
// iki ben muncul pas di uncheck
else {
setHide(0);
}
}
//iki keterangn ongko.ne
/* 0 for VISIBLE
/* 4 for INVISIBLE
/* 8 for GONE
*/
// iki ngirim perintah ning MyLayout.Java
public void setHide(int value)
{
Intent i = new Intent();
i.setAction("HIDE_LAYOUT");
i.putExtra("HIDE", value);
getContext().sendBroadcast(i);
}
// java ini hanya bisa di pake sekali .. jadi kalo mau bikin checkbok yg kedua
// harus bikin kode java lagi .. tinggal copas trz edit² sedikit
public int setResource(String name, String Type)
{
return getContext().getResources().getIdentifier(name, Type, getContext().getPackageName());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment