이 라이브러리를 사용하여 예지 버튼을 사용합니다. https://github.com/GwonHyeok/StickySwitch토글을 선택하거나 선택한 항목 값을 문자열로 전환 하시겠습니까?
전환 항목을 남성 또는 여성 값으로 문자열로 가져올 수있는 방법은 무엇입니까?
MainActivity :
public class MainActivity extends AppCompatActivity {
private final String TAG = MainActivity.class.getSimpleName();
private EditText textview;
@SuppressLint("WrongViewCast")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Set Selected Change Listener
StickySwitch stickySwitch = (StickySwitch) findViewById(R.id.sticky_switch);
stickySwitch.setOnSelectedChangeListener(new StickySwitch.OnSelectedChangeListener() {
@Override
public void onSelectedChange(@NotNull StickySwitch.Direction direction) {
Log.d(TAG, "Now Selected : " + direction.name());
}
});
}
}
XML 파일 :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBackground"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:backgroundTint="#fff"
tools:context="io.ghyeok.stickyswitchdemo.MainActivity">
<io.ghyeok.stickyswitch.widget.StickySwitch
android:id="@+id/sticky_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:iconPadding="18dp"
app:iconSize="22dp"
app:leftIcon="@drawable/male"
app:leftText="Male"
app:rightIcon="@drawable/ic_action_name"
app:rightText="Female"
app:selectedTextSize="14sp"
app:sliderBackgroundColor="@color/colorSliderBackground"
app:switchColor="@color/colorSwitchColor"
app:textColor="@color/colorTextColor"
app:textSize="12sp" />
</RelativeLayout>
'direction.name을()'당신이 원하는 것입니다. 로그보기 :'Log.d (TAG, "Now Selected :"+ direction.name()); ' –
이것은 왼쪽과 오른쪽으로 나에게 줄 것입니다. 남성 또는 여성을 문자열 –
에 저장하고'String value; if (direction.name(). equals ("LEFT")) {value = "Male"; } else {value = "Female";}' –