Skip to content

Commit

Permalink
add listener control
Browse files Browse the repository at this point in the history
  • Loading branch information
SPSpisoft committed Oct 10, 2019
1 parent 156f3ef commit ec46e1b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
11 changes: 11 additions & 0 deletions app/src/main/java/com/spisoft/spsgenderswitch/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.Toast;

import com.spisoft.spsswitch.SpGenderSwitch;

public class MainActivity extends AppCompatActivity {

@Override
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();
}
});
}
}
10 changes: 5 additions & 5 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
tools:context=".MainActivity">

<com.spisoft.spsswitch.SpGenderSwitch
android:id="@+id/met"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:SwitchSize="@dimen/sps_lpr_sz_50"
app:TitleFemale="@string/title_female"
app:TitleMale="@string/title_male"
app:TitleGender="@string/title_gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:ignore="MissingConstraints">
</com.spisoft.spsswitch.SpGenderSwitch>
app:TitleMale="@string/title_male"
tools:ignore="MissingConstraints"></com.spisoft.spsswitch.SpGenderSwitch>

</androidx.constraintlayout.widget.ConstraintLayout>
11 changes: 11 additions & 0 deletions spgender/src/main/java/com/spisoft/spsswitch/SpGenderSwitch.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -102,6 +111,8 @@ public void onAnimationEnd(Animation animation) {
mVal = GENRE_FEMALE;
}
SwitchView(mVal);
if(mListener!=null)
mListener.onEvent();
}

@Override
Expand Down

0 comments on commit ec46e1b

Please sign in to comment.