这是我想要使用按钮调用其他类的类。 bTicketRes
按钮和bAddBusData
工作正常,但第三个按钮,bEditSms
点击后,应用就会兑现。
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
switch(view.getId())
{
case R.id.bTicketRes:
TicketReservationView.setDatabase(database);
Intent it = new Intent(MainView.this,TicketReservationView.class);
startActivity(it);
break;
case R.id.bAddBusData:
BusDataManager.setDatabase(database);
Intent ib = new Intent(MainView.this, BusDataManager.class);
startActivity(ib);
break;
case R.id.bEditSms:
CustomSms.setDatabase(database);
Intent is = new Intent(MainView.this,CustomSms.class);
startActivity(is);
break;
这是我想用上面的课程中的按钮调用的课程
public class CustomSms extends Activity implements OnClickListener {
private static Database database;
private Button bSaveSms,bBack1;
private EditText customSms,timeDelay;
private SQLiteDatabase db;
public String savSms, timeDly;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.edit_sms);
customSms = (EditText)findViewById(R.id.etcustomSms);
timeDelay = (EditText)findViewById(R.id.ettimeDelay);
bSaveSms = (Button)findViewById(R.id.bSaveSms);
bBack1 = (Button)findViewById(R.id.bBack1);
bSaveSms.setOnClickListener(this);
bBack1.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId())
{
case R.id.bSaveSms:
db = database.getWritableDatabase();
database.deleteOld(db, savSms, timeDly);
savSms = customSms.getText().toString();
timeDly= timeDelay.getText().toString();
database.insert_message_data(savSms, timeDly, db);
showToast("Message Saved Successfully");
//Toast.makeText(v.getContext(), "Data Saved Successfully", Toast.LENGTH_SHORT).show();
db.close();
break;
case R.id.bBack1:
customSms.setText("");
timeDelay.setText("");
Intent is = new Intent(CustomSms.this, MainView.class);
startActivity(is);
break;
}
}
public static void setDatabase(Database dbase) {
// TODO Auto-generated method stub
database = dbase;
}
public void showToast(final String title)
{
final View view = getLayoutInflater().inflate(R.layout.toast_layout, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
TextView tv = (TextView)view.findViewById(R.id.toastTitle);
final AlertDialog ad = alertDialogBuilder.create();
ad.setTitle("Notification");
ad.setView(view);
tv.setText(title);
ad.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
ad.dismiss();
}
});
ad.show();
}
当我单击上面的类中的按钮来调用下面的类时,突然应用程序崩溃并重新启动上面的类。我希望在上面的课程
按下按钮时调用下面的课程