StoreData.java
public class StoreData {
private static StoreData mInstance;
private static Context mCtx;
private static final String SHARED_PREF_NAME = "storehighscore";
private static final String KEY_FIRSTNAME = "firstname";
private static final String KEY_LASTNAME = "lastname";
private static final String KEY_SCORE = "score";
private StoreData(Context context) {
mCtx = context;
}
public static synchronized StoreData getInstance(Context context) {
if (mInstance == null) {
mInstance = new StoreData(context);
}
return mInstance;
}
public boolean userHighScore(int firstname, String lastname, String score){
SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt(KEY_FIRSTNAME, firstname);
editor.putString(KEY_LASTNAME, lastname);
editor.putString(KEY_SCORE, score);
editor.apply();
return true;
}
public String getFirstName(){
SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getString(KEY_FIRSTNAME, null);
}
public String getLastName(){
SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getString(KEY_LASTNAME, null);
}
public String getPlayerScore(){
SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getString(KEY_SCORE, null);
}
}
ScoreTable.java
public class ScoreTable extends AppCompatActivity {
private TextView viewFirstName;
private TextView viewLastName;
private TextView viewPlayerScore;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_score_table);
viewFirstName = findViewById(R.id.viewFirstName);
viewLastName = findViewById(R.id.viewLastName);
viewPlayerScore = findViewById(R.id.viewPlayerScore);
viewFirstName.setText(StoreData.getInstance(this).getFirstName());
viewLastName.setText(StoreData.getInstance(this).getLastName());
viewPlayerScore.setText(StoreData.getInstance(this).getPlayerScore());
}
}
在此处查看完整的代码:Code
phpMyAdmin表
我无法将phpMyAdmin中存储的数据显示到我的应用程序中。我知道如何将数据存储到phpMyAdmin中,但是我需要有关如何将数据显示到我的App中的帮助。