我添加了一个edittext来查看按钮单击,然后我想在SQLite数据库中插入值。到目前为止,我已经尝试将此代码应用于新的EditText,但它们是水平创建的,而不是垂直创建的。另外我该如何管理ContentValues来插入添加的EditText的数据?
public void Add(View v) {
EditText et=new EditText(cnt);
linear.addView(et);
}
为了将您的edittext垂直添加到布局中,您可以尝试使用以下代码;我假设您正在使用LinearLayout:
LinearLayout root = (LinearLayout) findViewById(R.id.your_layout_id);
LinearLayout dynamic_component = new LinearLayout(this);
dynamic_component.setOrientation(LinearLayout.VERTICAL);
dynamic_component.addView(et);
root.addView(dynamic_component);
如果我理解正确,则可以尝试以下代码:
ContentValues values = new ContentValues();
values.put(YOU_KEY, text);
database.insert(YOUR_TABLE_NAME, null, values);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句