2010-11-01 63 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移动字符串称号。

相关问题