private Table income;
private Table expense;
String title,comment;
int amount;
EditText add;
Button add_btn;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
DatabaseHelper helper = new DatabaseHelper(this);
SQLiteDatabase db = helper.getWritableDatabase();
expense = new Table(db,helper.TABLE_1);
income = new Table(db,helper.TABLE_2);
add_btn = (Button)findViewById(R.id.add_btn);
add = (EditText)findViewById(R.id.add);
add_btn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
title = add.getText().toString();
income.insertTable(title, 100, " test");
expense.insertTable("another title", 50, "blah blah");
}
}
这是一个正确的答案,我不得不从的onCreate到的onClick移动字符串称号。
你想要插入什么类型的表格?数据库? – 2010-11-01 17:31:02
该表格为:标题STRING,金额INT,注释STRING; – Tsunaze 2010-11-01 17:34:37
我试过了:income.insertTable(title,100,“test”);其中收入是一个表对象,并且其中用于insertTable的梅索德是这样的:\t公共无效insertTable(字符串标题,INT量,字符串评论){ \t \t字符串SQL =“INSERT INTO “+ getTbName()+”(标题,金额,评论)VALUES('“+ title +”',“+ amount +”,'“+ comment +”')“; \t \t getDb()。execSQL(sql); \t} – Tsunaze 2010-11-01 17:35:47