diff --git a/app/src/main/java/com/spisoft/spsgenderswitch/MainActivity.java b/app/src/main/java/com/spisoft/spsgenderswitch/MainActivity.java index 401c8fa..3b32f09 100644 --- a/app/src/main/java/com/spisoft/spsgenderswitch/MainActivity.java +++ b/app/src/main/java/com/spisoft/spsgenderswitch/MainActivity.java @@ -3,6 +3,9 @@ import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; +import android.widget.Toast; + +import com.spisoft.spsswitch.SpGenderSwitch; public class MainActivity extends AppCompatActivity { @@ -10,5 +13,13 @@ public class MainActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + + final SpGenderSwitch Met = findViewById(R.id.met); + Met.setChangeValueListener(new SpGenderSwitch.OnChangeValueListener() { + public void onEvent() { + //do whatever you want to do when the event is performed. + Toast.makeText(MainActivity.this, Met.GetText(), Toast.LENGTH_SHORT).show(); + } + }); } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 3cc01b7..6d7b39d 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -7,13 +7,13 @@ tools:context=".MainActivity"> - + app:TitleMale="@string/title_male" + tools:ignore="MissingConstraints"> \ No newline at end of file diff --git a/spgender/src/main/java/com/spisoft/spsswitch/SpGenderSwitch.java b/spgender/src/main/java/com/spisoft/spsswitch/SpGenderSwitch.java index 92299dd..4dfe021 100644 --- a/spgender/src/main/java/com/spisoft/spsswitch/SpGenderSwitch.java +++ b/spgender/src/main/java/com/spisoft/spsswitch/SpGenderSwitch.java @@ -25,6 +25,15 @@ public class SpGenderSwitch extends RelativeLayout { private TextView iText; private String TitleGender, TitleMale, TitleFemale; private int TextColor; + OnChangeValueListener mListener; + + public interface OnChangeValueListener { + void onEvent(); + } + + public void setChangeValueListener(OnChangeValueListener eventListener) { + mListener = eventListener; + } public SpGenderSwitch(Context context) { super(context); @@ -102,6 +111,8 @@ public void onAnimationEnd(Animation animation) { mVal = GENRE_FEMALE; } SwitchView(mVal); + if(mListener!=null) + mListener.onEvent(); } @Override