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