我想从 RechargeActivity.java 文件中调用 inserttable 方法,该文件的定义位于另一个 TryUIOpenHelper.java 中,我的数据库和表是在其中创建的。我想知道更好的方法。请帮忙
public class RechargeActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.rechtable);
RadioButton rb1 = (RadioButton) findViewById(R.id.rtt1);
RadioButton rb2 = (RadioButton) findViewById(R.id.rtt2);
final TextView amount = (TextView)findViewById(R.id.amount1);
final TextView talktime = (TextView)findViewById(R.id.talktime1);
final TextView validity = (TextView)findViewById(R.id.validity1);
final Button button = (Button) findViewById(R.id.done);
final TryUIOpenHelper helper=new TryUIOpenHelper(this);
final SQLiteDatabase dbDatabase=helper.getWritableDatabase();
final Date date = new Date();
Calendar now = Calendar.getInstance();
int year = now.get(Calendar.YEAR);
int month = now.get(Calendar.MONTH); // 0 to 11
int day = now.get(Calendar.DAY_OF_MONTH);
String val=""+(day)+"/"+(month+1)+"/"+(year+1)+"";
validity.setText(val);
try{
rb1.setOnClickListener( new OnClickListener ()
{
public void onClick(View v)
{
//Error here: The method inserttable(SQLiteDatabase) is undefined for the type new View.OnClickListener(){}
inserttable(dbDatabase);
}
});
}
catch(Exception e)
{
System.out.println("Exception:"+e);
}
rb2.setOnClickListener( new OnClickListener ()
{
public void onClick(View v)
{
} } );
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final Intent intent =
new Intent(RechargeActivity.this, NumForRecharge.class);
startActivity(intent);
}
});
//db.close();
}
}