简体   繁体   English

Android:如何将R.String数据发送到SQLlite数据库并检索它

[英]Android: How to send R.String Data into SQLlite Database and retrieve it

Hi how to send the String value which is in R.String.XXXX into database, i tried as below but getting address instead of the actual string content. 嗨,如何将R.String.XXXX中的String值发送到数据库中,我尝试如下进行操作,但获取地址而不是实际的字符串内容。

In my class 在我班上

 DatabaseHelper.getInstance(Aboutipc_fragment.this).addAboutData(R.string.aboutcontent, "haresh");

In my Database Helper class 在我的数据库助手类中

public void addAboutData(int aboutcontent,String string) {
        ContentValues cv = new ContentValues();

        //System.out.println("geting notes from the database===== "+str);
        cv.put(KEY_ABOUTCONTENT, aboutcontent);
        cv.put(KEY_VALUE,string);
        db.insert(CREATE_ABOUTIPC_TABLE, null, cv);

    }

I am fetching Data As below 我正在获取数据如下

public Cursor fetchcontentvalues() {
        Cursor c = null;
         c = db.query(CREATE_ABOUTIPC_TABLE, new String[] {KEY_ABOUTCONTENT}, null, null, null, null,null);
        //moving to the first note
        //c.moveToFirst();
         c.moveToPosition(0);
        System.out.println("getting notes from the database"+c.getString(0));

        return c;

    }

Output 产量

getting notes from the database 2131099663

The system out statement is giving some address value i want to display the actual content of the string. 系统输出语句给出了一些我想显示字符串实际内容的地址值。

this is very simple 这很简单

get strings from r.string you can use method getString which return a String Value 从r.string获取字符串,可以使用方法getString返回字符串值

String a=getString(R.string.name);

in your method you can use 在您的方法中,您可以使用

addAboutData(getString(R.string.name), "haresh");

Use the following: 使用以下内容:

String aboutContent = getResources().getString(R.string.xxxx);

Change your addAboutData method as below 如下更改您的addAboutData方法

 public void addAboutData(String aboutcontent,String string) {
        ContentValues cv = new ContentValues();


        cv.put(KEY_ABOUTCONTENT, aboutcontent);
        cv.put(KEY_VALUE,string);
        db.insert(CREATE_ABOUTIPC_TABLE, null, cv);

    }

Then fetch data using 然后使用获取数据

public Cursor fetchcontentvalues() {
        Cursor c = null;
         c = db.query(CREATE_ABOUTIPC_TABLE, new String[] {KEY_ABOUTCONTENT}, null, null, null, null,null);
        //moving to the first note
        //c.moveToFirst();
         c.moveToPosition(0);
        System.out.println("getting notes from the database"+c.getString(0));

        return c;

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM