屏幕旋转时的按钮可见性不适用于多个按钮

时间:2013-12-02 14:54:57

标签: android android-listview

我正在尝试在屏幕旋转时恢复textView和按钮可见性状态中的字符串。如果我只使用一个按钮并注释掉其余按钮,它就可以工作。但不适用于所有按钮。请提出任何可能的原因。

@Override
public void onSaveInstanceState(Bundle outInstanceState) {  
super.onSaveInstanceState(outInstanceState);

outInstanceState.putString(savedName, colorView.getText().toString());
outInstanceState.putInt(savedWhiteBtn, (Integer) whiteColorButton.getVisibility());
outInstanceState.putInt(savedBlackBtn, (Integer) blackColorButton.getVisibility());
outInstanceState.putInt(savedRedBtn, (Integer) redColorButton.getVisibility());
outInstanceState.putInt(savedGreenBtn, (Integer) greenColorButton.getVisibility());
outInstanceState.putInt(savedYellowBtn, (Integer) yellowColorButton.getVisibility());
}   


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); 

colorView = (TextView) findViewById(R.id.textView1);
whiteColorButton = (Button) findViewById(R.id.buttonWhite);
blackColorButton = (Button) findViewById(R.id.buttonBlack);
redColorButton = (Button) findViewById(R.id.buttonRed);
yellowColorButton = (Button) findViewById(R.id.buttonYellow);
greenColorButton = (Button) findViewById(R.id.buttonGreen);

if(savedInstanceState != null){
    colorView.setText(savedInstanceState.getString(savedName));
    whiteColorButton.setVisibility(savedInstanceState.getInt(savedWhiteBtn));
    blackColorButton.setVisibility(savedInstanceState.getInt(savedBlackBtn));
    redColorButton.setVisibility(savedInstanceState.getInt(savedRedBtn));           
    greenColorButton.setVisibility(savedInstanceState.getInt(savedGreenBtn));
    yellowColorButton.setVisibility(savedInstanceState.getInt(savedYellowBtn));
}
else{
    colorView.setText(getString(R.string.strStart));
}
}

0 个答案:

没有答案