Я просто пытаюсь сделать один пункт Меню Навигационного Ящика для определенного вида.Я добавил два textView соответственно слева и справа.И SwitchCompat.Но SwitchCompat не работает.Я просто пытаюсь отправить одно сообщение для теста.
Я искал много ресурсов, но ничего подобного не смог найти.Это плохая практика?или не хорошо использовать?
Вот мои коды:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="4"
android:text="Pay" />
<android.support.v7.widget.SwitchCompat
android:id="@+id/paymentMethod"
android:layout_width="35dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:theme="@style/SelectionSwitch" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_weight="4"
android:text="Card" />
</LinearLayout>
В моей активности:
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
toolbarMenu.findItem(R.id.menu_item_search).setVisible(id == R.id.nav_camera);
Fragment fragment = null;
Class fragmentClass = null;
if (id == R.id.nav_camera) {
View view = item.getActionView();
SwitchCompat payMethod = view.findViewById(R.id.paymentMethod);
payMethod.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Toast.makeText(ActivityHome.this, "TEST", Toast.LENGTH_SHORT).show();
}
На самом деле после нажатия более 10 раз это работает, но не могу понять, почему.