本文介绍了如何多行的EditText存入SQLiteDatabase? [ANDROID]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在一个应用程序的工作,我已经2多行的EditText,我需要将它们存储到数据库中。我只知道如何存储单行的EditText。
I'm working on an application where I've 2 Multiline EditText and I need to store them into database. i only know how to store the single line EditText.
下面是我的codeS用于插入数据库:
Here is my codes for inserting into database:
btnSave = (Button) findViewById(R.id.btnSave);
btnSave.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
//startActivityForResult(new Intent(Intent.ACTION_PICK),PICK_CONTACT);
likeDB.open();
long likes_id;
Spinner nameSpinner = (Spinner) findViewById(R.id.nameSpinner);
String NameValue = nameSpinner.getSelectedItem().toString();
EditText txtLikes = (EditText) findViewById(R.id.txtLikes);
String LikesValue = txtLikes.getText().toString();
likes_id = likeDB.insertLikes(NameValue, LikesValue);
likeDB.close();
dislikeDB.open();
long dislikes_id;
Spinner names = (Spinner) findViewById(R.id.nameSpinner);
String NamesValue = names.getSelectedItem().toString();
EditText txtDislikes = (EditText) findViewById(R.id.txtDislikes);
String DislikesValue = txtDislikes.getText().toString();
dislikes_id = dislikeDB.insertDislikes(NamesValue, DislikesValue);
Toast.makeText(getBaseContext(),
"Your information is saved successfully!", Toast.LENGTH_SHORT).show();
dislikeDB.close();
}
});
这在code,我已经声明了LikeDBAdapter和DislikesDBAdapter在上面的onCreate()方法:
This the code where I've declared the LikeDBAdapter and DislikesDBAdapter above the onCreate() method:
LikesDBAdapter likeDB = new LikesDBAdapter(this);
DislikesDBAdapter dislikeDB = new DislikesDBAdapter(this);
我需要这方面的帮助。任何帮助将AP preciated。谢谢!
结果
=)
I need help with this. Any help will be appreciated. Thanks!
=)
推荐答案
在您的dbHelper类设置的方法和
使用 ContentValues
,例如:
set a method on your dbHelper class anduse a ContentValues
, e.g :
public boolean createNote(String VALUE_1 , String VALUE_2) {
ContentValues initValue = new ContentValues();
initValue.put(COLUMN_NAME_1 , VALUE_1);
initValue.put(COLUMN_NAME_2 , VALUE_2);
return mDb.insert(YOUR_TABLE_NAME , null, initValue) > 0;
}
这篇关于如何多行的EditText存入SQLiteDatabase? [ANDROID]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!