So i used a editText called "add", when i click on the button he have to insert into a table a title (string) and amount(int) and comments (string) . the title is like this : String title = add.getText().toString(); But it does not appear in the table . Plus when i had forgotten the "getText()" it displayed : android.widge开发者_如何学运维t.EditText@43e41168 . I dont know why ... (Sorry for my bad english, i'm french ^^).
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");
}
}
this is the right answer, i had to move the String title from the onCreate to the onClick.
精彩评论