请帮帮我,代码如下
当我关闭并启动我的应用时,textview
始终为0。
修改
现在已添加完整代码。
TextView txt = (TextView)findViewById(R.id.textView23);
int mynum1 = ea1.TimeCounter++;
int mynum2 = ea2.TimeCounter++;
int mynum3 = ea3.TimeCounter++;
int mynum4 = ea4.TimeCounter++;
int mynum5 = ea5.TimeCounter++;
int mynum6 = ea6.TimeCounter++;
in = (mynum1) + (mynum2) + (mynum3) + (mynum4) + (mynum5) + (mynum6) ;
txt.setText(Integer.toString(in));
TextView tt = (TextView)findViewById(R.id.textView26);
SharedPreferences sps = getSharedPreferences(PREFS, 0);
String ss = sps.getString("Score", "Nothing Found");
tt.setText(ss);
Button btn = (Button)findViewById(R.id.button8);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TextView txt = (TextView)findViewById(R.id.textView23);
TextView tt = (TextView)findViewById(R.id.textView26);
if (Integer.parseInt(txt.getText().toString()) < Integer.parseInt(tt.getText().toString())) {
String current = txt.getText().toString();
SharedPreferences sp = getSharedPreferences(PREFS, 0);
SharedPreferences.Editor editor = sp.edit();
editor.putString("Score", in);
editor.commit();
tt.setText(current);
}
else if(Integer.parseInt(txt.getText().toString()) > Integer.parseInt(tt.getText().toString())) {
SharedPreferences sps = getSharedPreferences(PREFS, 0);
String ss = sps.getString("Score", "Nothing Found");
tt.setText(ss);
}
}
});
答案 0 :(得分:0)
所以现在我得到了答案
new Thread(new Runnable() {
public void run() {
TextView txt = (TextView)findViewById(R.id.textView23);
int mynum1 = ea1.TimeCounter++;
int mynum2 = ea2.TimeCounter++;
int mynum3 = ea3.TimeCounter++;
int mynum4 = ea4.TimeCounter++;
int mynum5 = ea5.TimeCounter++;
int mynum6 = ea6.TimeCounter++;
in = (mynum1) + (mynum2) + (mynum3) + (mynum4) + (mynum5) + (mynum6) ;
txt.setText(Integer.toString(in));
TextView tt = (TextView)findViewById(R.id.textView26);
SharedPreferences sps = getSharedPreferences(PREFS, 0);
String ss = sps.getString("Score", "0");
tt.setText(ss);
Button btn = (Button)findViewById(R.id.button8);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TextView txt = (TextView)findViewById(R.id.textView23);
TextView tt = (TextView)findViewById(R.id.textView26);
if (Integer.parseInt(txt.getText().toString()) > Integer.parseInt(tt.getText().toString())) {
String current = Integer.toString(in);
SharedPreferences sp = getSharedPreferences(PREFS, 0);
SharedPreferences.Editor editor = sp.edit();
editor.putString("Score", current);
editor.commit();
tt.setText(current);
}
else if(Integer.parseInt(txt.getText().toString()) < Integer.parseInt(tt.getText().toString())) {
SharedPreferences sps = getSharedPreferences(PREFS, 0);
String ss = sps.getString("Score", "Nothing Found");
tt.setText(ss);
}
}
});
}
}).start();
}