2010-11-01 68 views
1

所以我使用了一個名爲「add」的editText,當我點擊按鈕時他必須在表格中插入標題(字符串)和金額(int)和註釋(字符串) 。 標題是這樣的:String title = add.getText()。toString(); 但它沒有出現在表格中。 加上當我忘記它顯示的「getText()」時:[email protected]。 我不知道爲什麼... (對不起我英語不好,我是法國人^^)。我的字符串沒有出現在我的數據庫中

+0

你想要插入什麼類型的表格?數據庫? – 2010-11-01 17:31:02

+0

該表格爲:標題STRING,金額INT,註釋STRING; – Tsunaze 2010-11-01 17:34:37

+0

我試過了: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

回答

0
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移動字符串稱號。

相關問題