在程序中,我试图将类的上下文传递给 INTENT,但View.OnClickListener()
由于它包含在onClick()
方法中而被传递。我应该写什么而不是this
?
package com.calender;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
public class GoTo extends Activity{
Spinner sp;
EditText etyear;
Button submit;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.go_to);
sp = (Spinner) findViewById (R.id.spin);
etyear = (EditText) findViewById (R.id.editText1);
submit = (Button) findViewById (R.id.bsub);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent in = new Intent(this,NextCal.class);
Bundle bun = new Bundle();
bun.putString("month", sp.getSelectedItem().toString());
int y = Integer.parseInt(etyear.getText().toString());
bun.putInt("year", y);
in.putExtras(bun);
startActivity(in);
}
});
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}