daw fawf
daw fawf

Reputation: 47

sharedpref add strings into table

i trying to insert my string into my database tables ,but it doesnt appear, so any advice on this how do i string my text so it able to appear on android database table

btnplayer = (Button) findViewById(R.id.button1);
    tw1 = (TextView)findViewById(R.id.PX2);
    btnplayer.setOnClickListener(new View.OnClickListener() {
        SharedPreferences myPrefs = getSharedPreferences("PREF_COUNT", 0);
        SharedPreferences.Editor myEditor = myPrefs.edit();

        public void onClick(View v) {

            String Player = myPrefs.getString("tw1",name);          
            DataStorage.this.btnplayer.setText("add name [" + Player + "]");
            myEditor.putString("Player", Player);
            myEditor.commit();

Upvotes: 1

Views: 58

Answers (2)

user2376920
user2376920

Reputation: 242

Please make your question more clear.

If you want store your data in database in android, you can go for SQLite database available in android http://developer.android.com/training/basics/data-storage/databases.html
but I suggest use sharedpreferences if only strings need to store.

Upvotes: 1

Rajeev
Rajeev

Reputation: 1404

I didn't get the meaning behind this statement String Player = myPrefs.getString("tw1",name); if you already have stored the same value (first time there will be no value so you will getting back the default "name" and then you will again store that name with the new key called "Player"). Where are you storing "tw1"? Exactly what issue you are facing?

Upvotes: 0

Related Questions