Switch button - disable swipe function

后端 未结 6 573
名媛妹妹
名媛妹妹 2020-12-17 09:42

I have a switch button (actually is a custom one) and I want to disable the swipe functionality for some reason; I want the user to be able to click it only. Is

6条回答
  •  隐瞒了意图╮
    2020-12-17 10:09

    //This code works fine

    public class MainActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener { Switch my_switch;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        my_switch = (Switch) findViewById(R.id.my_switch);
        my_switch.setOnCheckedChangeListener(this);
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.my_switch:
                if(my_switch.isChecked())
                    my_switch.setChecked(true);                
                else           
                    my_switch.setChecked(true);
                break;
        }
    }
    

    }

提交回复
热议问题