This is described in the Dev Guide ( http://developer.android.com/guide/topics/ui/ui-events.html )
// Create an anonymous implementation of OnClickListener private OnClickListener mCorkyListener = new OnClickListener() { public void onClick(View v) { // do something when the button is clicked } }; protected void onCreate(Bundle savedValues) { ... // Capture our button from layout Button button = (Button)findViewById(R.id.corky); // Register the onClick listener with the implementation above button.setOnClickListener(mCorkyListener); ... } You can also do it inline if you wanted: button.setOnClickListener(new View.OnClickListener() { public void onClick(final View v) { // do something here } }); To call another Activity you can do something like this in your onClick: Intent i = new Intent(this, OtherActivityName.class); i.putExtra(String id, String value); // if needed to pass info between the two activities startActivityForResult(i,int id); --minuo On Sun, May 30, 2010 at 2:11 AM, lamia <elloumi.la...@gmail.com> wrote: > Good morning, > > I'm a beginner developer on Android. > > I created an UI with two EditText and a button. > I want to create an application using twitter (API JTwitter), the the > first stage is to connect to twitter. > > On myApp.java I use this: > > public class myApp extends Activity implements OnClickListener{ > Twitter twitter; > > EditText TLogin; > EditText TPassword; > Button Connect; > > public void onClick(View src) { > try{ > > String login = TLogin.getText().toString(); > String password = TPassword.getText().toString(); > if(!login.equals("") && !password.equals("")){ > twitter=new Twitter(login,password); > if(!twitter.isValidLogin()){ > > TLogin.setText("not valid"); > TPassword.setText("not valid"); > } > else > twitter.setStatus("Connected"); > } > > } > catch(Exception e){} > } > > public void onCreate(Bundle savedInstanceState) { > try{ > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > > // find views by id > Connect= (Button) findViewById(R.id.Connect); > TLogin = (EditText) findViewById(R.id.TLogin); > TPassword = (EditText) findViewById(R.id.TPassword); > > // Add listener > Connect.setOnClickListener(this); > } > catch(Exception e){} > } > } > > > When I run this, I get nothing... I can't find where is the problem :s > please help me :s > > Else, if I want to call an othor layout using this button, how can I > do it? > > > Thank you. > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en