请帮助!!我正在创造一个简单的游戏。 为此,我创建了一个自定义视图。
public class GameView extends View
我有一个打开游戏设置的按钮。所以我为此创建了一个对话框。 按下对话框按钮后,我在自定义视图中重新绘制。但它并不是立即令人耳目一新的观点。这需要几秒钟。
enter code here
public void settingFunction()
{
int musicOn=-1; int suitLevel = -1;
final Dialog endDialog = new Dialog(mycontext);
endDialog.setCancelable(false);
endDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
endDialog.setContentView(R.layout.settings);
TextView settingText = (TextView) endDialog.findViewById(R.id.textLayout);
TextView settingText1 = (TextView) endDialog.findViewById(R.id.textLayout_1);
Button nextButton = (Button) endDialog.findViewById(R.id.nextHandButton);
final Switch sw1 = (Switch) endDialog.findViewById(R.id.switch1);
RadioButton easy = (RadioButton) endDialog.findViewById(R.id.easy);
RadioButton medium = (RadioButton) endDialog.findViewById(R.id.medium);
RadioButton hard = (RadioButton) endDialog.findViewById(R.id.difficult);
//dbC.insertSetting("MUSIC",1);
String st = "MUSIC";
musicOn =dbC.readSetting( st);
suitLevel =dbC.readSetting( "SUIT");
int ct ;
//sw1.setChecked(true);
//Toast.makeText(mycontext," music" + musicOn ,Toast.LENGTH_SHORT).show();
if(musicOn ==1)
{
sw1.setChecked(true);
} else {sw1.setChecked(false);}
if(suitLevel ==1)
{
easy.setChecked(true);
} else if (suitLevel ==2)
{medium.setChecked(true);} else if (suitLevel==3) {easy.setChecked(true);}
endDialog.show();
sw1.setOnCheckedChangeListener(
new CompoundButton.OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if(isChecked)
{dbC.updateSetting("MUSIC",1);
}
else {dbC.updateSetting("MUSIC",0);}
}
}
);
nextButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
initalAnimation = 1;
endDialog.dismiss();
invalidate();
//alertUser();
}
});
}