我尝试保存卡片视图的可见性状态,起初我的视图消失了,但是如果用户按下按钮,卡片视图就会显示。有人可以帮助我并告诉我如何存储可见性,我找不到有关此主题的任何内容
太感谢了。
我尝试了 shardPrefs 但不起作用
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cv1= (CardView) findViewById(R.id.cv1);
cv2= (CardView) findViewById(R.id.cv2);
cv3= (CardView) findViewById(R.id.cv3);
cv4= (CardView) findViewById(R.id.cv4);
cv5= (CardView) findViewById(R.id.cv5);
cv6= (CardView) findViewById(R.id.cv6);
cv7= (CardView) findViewById(R.id.cv7);
cv8= (CardView) findViewById(R.id.cv8);
cv9= (CardView) findViewById(R.id.cv9);
AddBar = findViewById(R.id.AddBar);
AddVoorraad =findViewById(R.id.AddVoorraad);
AddBar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clickcount = clickcount + 1;
if (clickcount == 1) {
cv1.setVisibility(View.VISIBLE);
}
if (clickcount == 2) {
cv2.setVisibility(View.VISIBLE);
}
if (clickcount == 3) {
cv3.setVisibility(View.VISIBLE);
}
if (clickcount == 4) {
cv4.setVisibility(View.VISIBLE);
}
if (clickcount == 5) {
cv5.setVisibility(View.VISIBLE);
}
if (clickcount == 6) {
cv6.setVisibility(View.VISIBLE);
}
if (clickcount==7 ){
cv7.setVisibility(View.VISIBLE);
}
}
});
AddVoorraad.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clickcountV=clickcountV+1;
if (clickcountV==1) {
cv8.setVisibility(View.VISIBLE);
}
if (clickcount==2) {
cv9.setVisibility(View.VISIBLE);
}
}
});
catspeake
DIEA
慕盖茨4494581
相关分类