我使用的按钮没有响应click事件,我添加了onClickListener。我是android新手,请告诉我哪里出错了。
public class Welcome extends Activity implements OnClickListener{
EditText range;
Button submit;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState)
{
Log.i("MyActivity", "Entered ");
try
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
Button submit = (Button)findViewById(R.id.BtnSubmit);
EditText range= (EditText)findViewById(R.id.EditRange);
TextView title=(TextView)findViewById(R.id.txtTitle);
TextView notice=(TextView)findViewById(R.id.txtRange);
EditText EditRange = null;
String value= EditRange.getText().toString();
final Bundle bundle= new Bundle();
bundle.putString("param1",value);
submit.setOnClickListener((android.view.View.OnClickListener) this);
}
catch(Exception e)
{
//Log.d("My Activity",e.getMessage());
e.printStackTrace();
}
}
public void onClick(View v) {
Log.i("MyActivity", "Entered OnClick()");
// TODO Auto-generated method stub
String value= range.getText().toString();
final Bundle bundle= new Bundle();
bundle.putString("param1",value);
Toast.makeText(getBaseContext(), "Wait", Toast.LENGTH_SHORT).show();
Intent myIntent = new Intent(v.getContext(), RoutePath.class);
myIntent.putExtras(bundle);
startActivity(myIntent);
}
}
答案 0 :(得分:1)
只需输入setOnClickListener(Welcome.this)
答案 1 :(得分:1)
供您的活动使用 submit.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
在onClick()内放置你想要的任何内容。