我正在开发一个我有2个Multiline EditText的应用程序,我需要将它们存储到数据库中。我只知道如何存储单行EditText。
以下是我插入数据库的代码:
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();
}
});
这是我在onCreate()方法之上声明LikeDBAdapter和DislikesDBAdapter的代码:
LikesDBAdapter likeDB = new LikesDBAdapter(this);
DislikesDBAdapter dislikeDB = new DislikesDBAdapter(this);
我需要帮助。任何帮助将不胜感激。谢谢!
=)
答案 0 :(得分:0)
在dbHelper类上设置一个方法
使用ContentValues
,例如:
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;
}