[英]How to use Toggle Button to change the Onclick of a Button
嗨,我有一个“切换按钮”,当切换此按钮时,我会在单击时将其他“下一步按钮”设置为此
public void shuffleSong(View view)
{
//Call shuffle in the Songcollection
Song shuffle = SongCollection.shufflefunction(songId);
songId = shuffle.getId();
title = shuffle.getTitle();
artist = shuffle.getArtist();
fileLink = shuffle.getFileLink();
coverArt = shuffle.getCoverArt();
album=shuffle.getAlbum();
url = BASE_URL + fileLink;
displaySong(title, artist, coverArt);
stopActivities();
playOrPauseMusic(new View(this));
}
当不切换按钮时,我想将我的下一个按钮onclick设置为此
public void playNext(View view)
{
Song nextSong = SongCollection.getNextSong(songId);
if (nextSong != null) {
songId = nextSong.getId();
title = nextSong.getTitle();
artist = nextSong.getArtist();
fileLink = nextSong.getFileLink();
coverArt = nextSong.getCoverArt();
album=nextSong.getAlbum();
url = BASE_URL + fileLink;
displaySong(title, artist, coverArt);
stopActivities();
playOrPauseMusic(view);
}
}
但是我不知道该怎么做
若要检测用户何时激活按钮或开关,请创建一个CompoundButton.OnCheckedChangeListener对象,然后通过调用setOnCheckedChangeListener()将其分配给按钮。 例如:
ToggleButton toggle = (ToggleButton) findViewById(R.id.togglebutton);
toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
// The toggle is enabled, do whatever you want to do here
} else {
// The toggle is disabled, do whatever you want to do here
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.