我有这段代码可以在相应的数据库中添加数据。
public class RegisterActivity extends Activity implements OnClickListener {
SQLiteOpenHelper helper;
SQLiteDatabase dbs;
Button reg,exit;
EditText eid,ename,eno,ecourse;
TextView efee;
CheckBox java,net,php,and;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
eid=(EditText)findViewById(R.id.etid);
ename=(EditText)findViewById(R.id.etname);
eno=(EditText)findViewById(R.id.etmob);
efee=(TextView)findViewById(R.id.etfee);
efee.setText(""+ 0);
java=(CheckBox)findViewById(R.id.tvjava);
php=(CheckBox)findViewById(R.id.tvphp);
net=(CheckBox)findViewById(R.id.tv_net);
and=(CheckBox)findViewById(R.id.tvand);
reg=(Button)findViewById(R.id.tvreg);
exit=(Button)findViewById(R.id.tvcan);
reg.setOnClickListener(this);
exit.setOnClickListener(this);
java.setOnClickListener(this);
helper=new SQLiteOpenHelper(this,"AMS",null,1) {
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("create table Reg_Student(_id integer primary key autoincrement,name text,contact integer,java text,net text,php text,andr text,fee integer)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
};
dbs=helper.getWritableDatabase();
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ContentValues cv=new ContentValues();
int fees=0;
if(v == reg)
{
//ContentValues cv=new ContentValues();
cv.put("name",ename.getText().toString());
cv.put("contact",Integer.parseInt(eno.getText().toString()));
if(java.isChecked())
{
fees = fees + 5000;
efee.setText(String.valueOf(fees));
cv.put("java",java.getText().toString());
}
if(php.isChecked())
{
fees = fees + 2000;
efee.setText(String.valueOf(fees));
cv.put("php",php.getText().toString());
}
if(and.isChecked())
{
fees = fees + 4000;
efee.setText(String.valueOf(fees));
cv.put("andr",and.getText().toString());
}
if(net.isChecked())
{
fees = fees + 5000;
efee.setText(String.valueOf(fees));
cv.put("net",net.getText().toString());
}
cv.put("fee",fees);
long id = dbs.insert("Reg_Student", null, cv);
Toast.makeText(this, "Registered with id : "+id, Toast.LENGTH_LONG).show();
reg.setEnabled(false);
}
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
helper.close();
}
}
在这里,数据被添加到数据库中,但是当我选择一个特定的文本框时 setText 没有改变。
我是android新手,所以请帮我解决这个问题。