0

The button that i have used is not responding to the click event, i have added the onClickListener. i am new to android , plz tell me where am i going wrong.

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); } } 

2 Answers 2

1

in setOnClickListener just put setOnClickListener(Welcome.this)

Sign up to request clarification or add additional context in comments.

3 Comments

Skip the "Welcome ." part. Just pass "this" as parameter.
just put setOnClickListener(this)
just put welcome.this i think this should work.Also you will not get value in on click coz it is local to oncreate try to declare the string value above to onCreate.for EditText EditRange = null; String value= range.getText().toString(); try these
1

For your activity use submit.setOnClickListener(new View.OnClickListener() {

 @Override public void onClick(View v) { // TODO Auto-generated method stub } }); 

inside onClick() put whatever you want.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.