插入的EditText和放大器;微调的数据SQLite的? [英] Inserting EditText & Spinner data to SQLite?

查看:145
本文介绍了插入的EditText和放大器;微调的数据SQLite的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出如何捕获使用的EditText&放一个表单数据;飞旋的,并将其插入到一个SQLite数据库。我能写硬codeD属性,但是当我尝试使用它R.id.fieldName抛出一个错误,由于是一个整数副的字符串。

I'm trying to figure out how to capture data from a form using EditText & Spinner's and insert it into a SQLite database. I am able to write the hard coded attributes but when I try to use R.id.fieldName it throws an error due to being an Integer vice a String.

public class PetAdd extends Activity {
DBAdapter db = new DBAdapter(this);
private OnClickListener btnPetAddListener = new OnClickListener() {
    @Override
    public void onClick(View arg0) {
        db.open();
        long id;
        id = db.insertPet("name", "type", "breed", "sex", "notes");
         /**id = db.insertPet(R.id.petName, R.id.SpinnerPetType, R.id.petBreed, R.id.SpinnerPetGender, R.id.EditTextPetAddOptions);*/
        db.close();
    }
};

我还在努力学习所有这些东西,我的大脑是从看在线教程,范例和谷歌文档过多油炸。如果有人能告诉我如何做到这一点,或直接我一个巴尼风格的教程,休息下来,我明白这是怎么回事,它会是很大的AP preciated。

I'm still trying to learn all this stuff and my brain is fried from looking at a plethora of online tutorials, examples and Google documentation. If anyone can show me how to do this or direct me to a barney style tutorial that breaks it down for me to understand what's going on, it'd be greatly appreciated.

推荐答案

R.id.fieldName是数字参考项的活动(前提是你的布局的一部分)。

R.id.fieldName is a numeric reference to the item in your Activity (provided it's part of your layout).

您将需要调用findViewById(R.id.fieldName)获得refererene它。您还需要将其转换为正确的类型来看(在你的情况的EditText),然后调用gettext的()。的toString()对整个事情。

You'll need to call findViewById(R.id.fieldName) to get a refererene to it. You'll also need to cast it to the correct type of view (in your case EditText) and then call getText().toString() on the whole thing.

全部放在一起......

Putting it all together...

EditText myField = (EditText)findViewById(R.id.userName); //assuming you have a field named userName in your XML

String userNameValue = myField.getText().toString();

哦,欢迎到堆栈...不要忘记标记作为答案正确和及时投他们时,他们是有帮助的。

Oh, and welcome to Stack... don't forget to mark answers as correct and up-vote them when they're helpful.

这篇关于插入的EditText和放大器;微调的数据SQLite的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆