Thursday, January 3, 2013

Android-Different ways of implementing button

Create a button in xml:-

<Button
           android:id="@+id/login"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Login"
            android:onClick="login" />

and in Activity implement

public void login(View view) {
     
 }

(or)

final Button button = (Button) findViewById(R.id.login);
         button.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 // Perform action on click
             }
         });

(or)

public class TestActivity extends Activity implements OnClickListener {
@Override
 public void onClick(View v) {
  if (v.getId() == R.id.login) {
  //do some action
  }
 }

}

No comments:

Post a Comment