Issue
I am trying to use the switch button in my map activity app
I add the following code snippet in the onCreate method in my project but nothing happens when I click on the switch button
tourSwitch= (Switch) findViewById(R.id.tourswitch);
tourSwitch.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
if(tourSwitch.getText().toString().equals("ON"))
{
mapOverlays.remove(3);
}
else if(tourSwitch.getText().toString().equals("OFF"))
{
mapOverlays = mapView.getOverlays();
projection = mapView.getProjection();
mapOverlays.add(3, new TourGuide());
}
}
});
If anyone could please help me...thanks
Solution
I think that you are using the wrong listener. You should use setOnCheckedChangeListener (Switch
is a subclass of CompoundButton
):
tourSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// Do Something
}
});
Answered By - Jonathan Naguin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.