显示从编辑文本到微调器的项目并保存到数据库
我想显示从 editext 到 spinner 的一个项目并保存到数据库...如何在数据库中存储项目...
我的代码:
spinner 填充
final DBAdapter db = new DBAdapter(this);
db.open();
Spinner spin = (Spinner) findViewById(R.id.spinner1);
AdapterCountries = new ArrayAdapter<CharSequence>(this,
android.R.layout.simple_spinner_item);
AdapterCountries.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(AdapterCountries);
Cursor cursor = db.getAllTitles1();
while (cursor.moveToNext()){
results=cursor.getString(2);
AdapterCountries.add(results);
}
db.close();
,
Button d_ok=(Button)dialog.findViewById(R.id.d_ok);
final EditText filename=(EditText)dialog.findViewById(R.id.filename);
d_ok.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
//
}});
任何人都可以帮助我举例
谢谢...
I want to show an item from editext to spinner and save to db... how to store item in the db...
my code :
spinner populating
final DBAdapter db = new DBAdapter(this);
db.open();
Spinner spin = (Spinner) findViewById(R.id.spinner1);
AdapterCountries = new ArrayAdapter<CharSequence>(this,
android.R.layout.simple_spinner_item);
AdapterCountries.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(AdapterCountries);
Cursor cursor = db.getAllTitles1();
while (cursor.moveToNext()){
results=cursor.getString(2);
AdapterCountries.add(results);
}
db.close();
and
Button d_ok=(Button)dialog.findViewById(R.id.d_ok);
final EditText filename=(EditText)dialog.findViewById(R.id.filename);
d_ok.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
//
}});
any one can help me with example
Thank you...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您还没有,那么我真的认为您应该有一个扩展给定 SQLiteOpenHelper Android 类的 SQL 帮助器类。它确实简化了数据库操作。请参阅:http://developer.android.com/guide/topics /data/data-storage.html#db
强烈推荐。
如果您设置了帮助程序类,并且该类的实例设置为 SQLHelper sql = new SQLHelper(this); ,那么修改数据库就相当简单了。您应该设置一个从按钮 onClickListener 调用的方法(并且可能在 AsyncTask 或后台线程中运行它):
然后调用该方法并将其从侦听器添加到您的适配器:
If you don't have one already, then I really think you should have a SQL helper class extending the given SQLiteOpenHelper Android class. It really simplifies DB operations. See: http://developer.android.com/guide/topics/data/data-storage.html#db
It's heavily recommended.
If you set up the helper class and the instance of that class is set up like
SQLHelper sql = new SQLHelper(this);
then modifying the database is fairly simple. You should set up a method that you call from your buttons onClickListener (and possibly run it in an AsyncTask or a background thread):And then call the method and add it to your adapter from the listener: