2011-03-16 247 views
0

我用的按鈕沒有響應點擊事件,我添加了onClickListener。我是新來的機器人,請告訴我哪裏錯了。按鈕沒有響應點擊事件

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

回答

1

在setOnClickListener只是把setOnClickListener(Welcome.this)

+0

Thnx Sumant ,,但即使這不起作用 – user662452

+0

跳過「歡迎。」部分。只需傳遞「this」作爲參數。 – Flo

+0

只是把'setOnClickListener(this)' – tbruyelle

1

爲了您的活動中使用 submit.setOnClickListener(新View.OnClickListener(){

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

     } 
    }); 

內部的onClick()把任何