开发者

saving data from textview

I created a DB in my application. I have one TextView in my application开发者_如何学Go, I need to save the data whatever in textview. How can I do that?


Shared Preferences will be helpful to you to store data. Here is the docs.

http://developer.android.com/reference/android/content/SharedPreferences.html

And the text from textview can be obtained using

String textToStore = textview.getText().toString;


In your database adapter class create a method to insert a single value in your database like

public void insert(String data)
    {
        ContentValues in=new ContentValues();
        in.put("data", data);

        db.insert(table_name, null, in);
    }

Create a object of your adapter class and then call the method insert with the value of your edit text.

public void insert(Object data)
    {
        ContentValues in=new ContentValues();
        //in.put("data", (String) data);
        in.putAll((ContentValues) data);

        db.insert(table_name, null, in);
    } 

Here you can can pass any object to insert in the database.


get data from textview:

String var = yourtextview.getText().toString();

save this variable as per your need..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜