我有一个警报对话框,在进入活动之前弹出窗口。这是一个警告对话框,其中包含Don't Show this again
的chechbox。我添加了一个读取所有术语的mp3文件。我尝试了所有可能的东西,它没有用。这就是我想要做的。
单击I Agree
按钮时,应停止正在播放的声音文件。
当用户点击时不再显示此复选框时,再次输入活动后声音不会播放。
每一条线索都会受到极大的关注。 Thnx提前。
}
@Override
protected void onResume() {
AlertDialog.Builder warning1 = new AlertDialog.Builder(this);
LayoutInflater warning1Inflater = LayoutInflater.from(this);
View myLayout = warning1Inflater.inflate(R.layout.warning_layout, null);
final CheckBox dontShowAgain = (CheckBox) myLayout.findViewById(R.id.skip);
warning1 .setCancelable(false);
warning1 .setView(myLayout);
warning1 .setTitle("Warning!");
MediaPlayer mp = MediaPlayer.create(StartDialog.this,R.raw.terms);
mp.start();
warning1 .setIcon(R.drawable.alert1);
warning1 .setPositiveButton("I Agree", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String checkBoxResult = "NOT checked";
if (dontShowAgain.isChecked())
checkBoxResult = "checked";
String PREFS_NAME = null;
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("skipMessage", checkBoxResult);
editor.commit();
MediaPlayer mp = MediaPlayer.create(StartDialog.this,R.raw.terms);
mp.stop();
return;
}
});
String PREFS_NAME = null;
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
String skipMessage = settings.getString("skipMessage", "NOT checked");
if (!skipMessage.equals("checked"))
warning1 .show();
super.onResume();
答案 0 :(得分:0)
你应该实现这个。
dontShowAgain.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
switch (buttonView.getId()) {
case R.id.checkBox:
checkBoxResult = "checked";
String PREFS_NAME = "";
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("skipMessage", checkBoxResult);
editor.commit();
break;
}
}
});
点击OK
按钮,您必须关闭Dialog
。
现在您可以通过
进行检查 SharedPreferences sp = getSharedPreferences("PREFS_NAME", 0);
boolean hasBeenChecked = sp.getBoolean("skipMessage", false);
if (!hasBeenChecked) {
show your dialog here
} else {
// do your stuff here
}