我有一个奇怪的问题,我EditText
在 xml 中有几个框,我给了它们默认值。我也在使用共享首选项,其中我保存用户输入的值。
问题是在模拟器中EditText
工作正常但在真实的物理设备上值是空的,我错过了什么吗???
<EditText
android:id="@+id/etTRQPO"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal"
android:singleLine="true"
android:text="15">
</EditText>
爪哇代码
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Getacc extends Activity {
Button save6;
EditText edtTRQPO, edtTRQGE, edtTRQFW, edtTRQGR, edtTRQBN, edtTRQLT,
edtTRQPP, edtTRQCG;
int tV, tW, tX, counterAC;
String tsTRQPO, tsTRQGE, tsTRQFW, tsTRQGR, tsTRQBN, tsTRQLT, tsTRQPP,
tsTRQCG;
public static String FILE1 = "MyPrefsFile";
SharedPreferences abcPref;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.getacc);
save6 = (Button) findViewById(R.id.btGoresult);
edtTRQPO = (EditText) findViewById(R.id.etTRQPO);
edtTRQGE = (EditText) findViewById(R.id.etTRQGE);
edtTRQFW = (EditText) findViewById(R.id.etTRQFW);
edtTRQGR = (EditText) findViewById(R.id.etTRQGR);
edtTRQBN = (EditText) findViewById(R.id.etTRQBN);
edtTRQLT = (EditText) findViewById(R.id.etTRQLT);
edtTRQPP = (EditText) findViewById(R.id.etTRQPP);
edtTRQCG = (EditText) findViewById(R.id.etTRQCG);
abcPref = getSharedPreferences(FILE1, 0);
edtTRQPO.setText(abcPref.getString("tsTRQPO", ""));
edtTRQGE.setText(abcPref.getString("tsTRQGE", ""));
edtTRQFW.setText(abcPref.getString("tsTRQFW", ""));
edtTRQGR.setText(abcPref.getString("tsTRQGR", ""));
edtTRQBN.setText(abcPref.getString("tsTRQBN", ""));
edtTRQLT.setText(abcPref.getString("tsTRQLT", ""));
edtTRQPP.setText(abcPref.getString("tsTRQPP", ""));
edtTRQCG.setText(abcPref.getString("tsTRQCG", ""));
save6.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if ((!edtTRQPO.getText().toString().equals(""))
&& (!edtTRQGE.getText().toString().equals(""))
&& (!edtTRQFW.getText().toString().equals(""))
&& (!edtTRQGR.getText().toString().equals(""))
&& (!edtTRQBN.getText().toString().equals(""))
&& (!edtTRQLT.getText().toString().equals(""))
&& (!edtTRQPP.getText().toString().equals(""))
&& (!edtTRQCG.getText().toString().equals(""))) {
// TODO Auto-generated method stub
counterAC =1;
abcPref = getSharedPreferences(FILE1, 0);
SharedPreferences.Editor editor = abcPref.edit();
editor.putString("tsTRQPO", edtTRQPO.getText().toString());
editor.putString("tsTRQGE", edtTRQGE.getText().toString());
editor.putString("tsTRQFW", edtTRQFW.getText().toString());
editor.putString("tsTRQGR", edtTRQGR.getText().toString());
editor.putString("tsTRQBN", edtTRQBN.getText().toString());
editor.putString("tsTRQLT", edtTRQLT.getText().toString());
editor.putString("tsTRQPP", edtTRQPP.getText().toString());
editor.putString("tsTRQCG", edtTRQCG.getText().toString());
editor.putInt("counterac", counterAC);
editor.commit();
Toast message = Toast.makeText(Getacc.this,
"Values are saved", 2000);
message.setGravity(Gravity.BOTTOM, 0, 0);
message.show();
Intent opentime = new Intent("com.sports.sport.TIME");
startActivity(opentime);
onPause();
} else {
Toast failz = Toast.makeText(Getacc.this,
"Values are not Entered", 2000);
failz.setGravity(Gravity.BOTTOM, 0, 0);
failz.show();
}
};
});
}
}