即使我重新启动应用程序或关闭应用程序并重新启动它(持久存储),我如何保存contadorliga
或转动的值?.setVisibility(View.VISIBLE);
我想保存int contadorliga
,correcto1.setVisibility(View.VISIBLE);
所以correcto2.setVisibility(View.VISIBLE);
每次我重新启动应用程序时,它都是最近一次。就像一个保存游戏。这是我的代码:
package com.fakur.android.futbolquiz;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class Liga extends Activity {
/** Called when the activity is first created. */
static final int LIGA = 0;
int contadorbarcelona = 0;
int contadormadrid = 0;
int contadorliga = 0;
ImageView about;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.liga);
TextView contador1 = (TextView) findViewById(R.id.contador1);
contador1.setText(contadorliga + "/20");
}
public void onBarcelonaClick(View botton) {
Intent intent = new Intent();
intent.setClass(this,Pregunta.class);
intent.putExtra("Barcelona", "Barcelona");
startActivityForResult(intent,LIGA);
}
public void onMadridClick(View botton) {
Intent intent = new Intent();
intent.setComponent(new ComponentName(this,Pregunta.class));
intent.putExtra("Madrid", "Madrid");
startActivityForResult(intent,LIGA);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
TextView contador1 = (TextView) findViewById(R.id.contador1);
ImageView correcto1 = (ImageView) findViewById(R.id.correcto1);
ImageView correcto2 = (ImageView) findViewById(R.id.correcto2);
if (requestCode == LIGA){
if (resultCode == 1) {
if(contadorbarcelona == 0){
correcto1.setVisibility(View.VISIBLE);
contadorliga++ ;
contadorbarcelona++;
}
}
if (resultCode == 2) {
if(contadormadrid == 0){
correcto2.setVisibility(View.VISIBLE);
contadorliga++ ;
contadormadrid++;
}
}
}
contador1.setText(contadorliga + "/20");
}