Skip to main content
Copy edited.
Source Link
Peter Mortensen
  • 31.6k
  • 22
  • 109
  • 133

I would rather go for the click handling in code than using the onClick attribute in xmlXML when working with fragments. This

This becomes even easier when migrating your activities to fragments. You can just call the click handler  (previously set to android:onClick in xmlXML) directly from each case block.

findViewById(R.id.button_login).setOnClickListener(clickListener);
...

OnClickListener clickListener = new OnClickListener() {
    @Override
    public void onClick(final View v) {
        switch(v.getId()) {
           case R.id.button_login:
              // whichWhich is supposed to be called automatically in your
              // in your activity, which has now changed to a fragment.
              onLoginClick(v);   
              break;

           case R.id.button_logout:
              ...
        }
    }
}

When it comes to handling clicks in fragments, this looks simpler to me than android:onClick.

I would rather go for the click handling in code than using the onClick attribute in xml when working with fragments. This becomes even easier when migrating your activities to fragments. You can just call the click handler(previously set to android:onClick in xml) directly from each case block.

findViewById(R.id.button_login).setOnClickListener(clickListener);
...

OnClickListener clickListener = new OnClickListener() {
    @Override
    public void onClick(final View v) {
        switch(v.getId()) {
           case R.id.button_login:
              // which is supposed to be called automatically
              // in your activity, which has now changed to a fragment.
              onLoginClick(v);   
              break;

           case R.id.button_logout:
              ...
        }
    }
}

When it comes to handling clicks in fragments, this looks simpler to me than android:onClick.

I would rather go for the click handling in code than using the onClick attribute in XML when working with fragments.

This becomes even easier when migrating your activities to fragments. You can just call the click handler  (previously set to android:onClick in XML) directly from each case block.

findViewById(R.id.button_login).setOnClickListener(clickListener);
...

OnClickListener clickListener = new OnClickListener() {
    @Override
    public void onClick(final View v) {
        switch(v.getId()) {
           case R.id.button_login:
              // Which is supposed to be called automatically in your
              // activity, which has now changed to a fragment.
              onLoginClick(v);
              break;

           case R.id.button_logout:
              ...
        }
    }
}

When it comes to handling clicks in fragments, this looks simpler to me than android:onClick.

deleted 2 characters in body
Source Link
Ron
  • 24.2k
  • 8
  • 57
  • 99

I would rather go for the click handling in code than using the onClick attribute in xml when working with fragments. This becomes even easier when migrating your activities to fragments. You can just call the click handler(previously set to android:onClick in xml) directly from each case block.

findViewById(R.id.button_login).setOnClickListener(clickListener);
...

OnClickListener clickListener = new OnClickListener() {
    @Override
    public void onClick(final View v) {
        switch(v.getId()) {
           case R.id.button_login:
              // which is supposed to be called automatically
              // in your activity, which has now changed to a fragment.
              onLoginClick(v);   
              break;

           case R.id.button_logout:
              ...
        }
    }
}

When it comes to handling clicks in fragments, this looks simpler to me than android:onClick.

This becomes even easier when migrating your activities to fragments. You can just call the click handler(previously set to android:onClick in xml) directly from each case block.

I would rather go for the click handling in code than using the onClick attribute in xml when working with fragments.

findViewById(R.id.button_login).setOnClickListener(clickListener);
...

OnClickListener clickListener = new OnClickListener() {
    @Override
    public void onClick(final View v) {
        switch(v.getId()) {
           case R.id.button_login:
              // which is supposed to be called automatically
              // in your activity, which has now changed to a fragment.
              onLoginClick(v);   
              break;

           case R.id.button_logout:
              ...
        }
    }
}

When it comes to handling clicks in fragments, this looks simpler to me than android:onClick.

This becomes even easier when migrating your activities to fragments. You can just call the click handler(previously set to android:onClick in xml) directly from each case block.

I would rather go for the click handling in code than using the onClick attribute in xml when working with fragments. This becomes even easier when migrating your activities to fragments. You can just call the click handler(previously set to android:onClick in xml) directly from each case block.

findViewById(R.id.button_login).setOnClickListener(clickListener);
...

OnClickListener clickListener = new OnClickListener() {
    @Override
    public void onClick(final View v) {
        switch(v.getId()) {
           case R.id.button_login:
              // which is supposed to be called automatically
              // in your activity, which has now changed to a fragment.
              onLoginClick(v);   
              break;

           case R.id.button_logout:
              ...
        }
    }
}

When it comes to handling clicks in fragments, this looks simpler to me than android:onClick.

added 252 characters in body
Source Link
Ron
  • 24.2k
  • 8
  • 57
  • 99

I would rather go for the click handling in code than using the onClick attribute in xml when working with fragments.

...
findViewById(R.id.button_login).setOnClickListener(clickListener);
...

OnClickListener clickListener = new OnClickListener() {
    @Override
    public void onClick(final View v) {
        switch(v.getId()) {
           case R.id.button_login:
              ..// which is supposed to be called automatically
              // in your activity, which has now changed to a fragment.
              onLoginClick(v);   
              break;

           case R.id.button_logout:
              ...
        }
    }
}

When it comes to handling clicks in fragments, this looks simpler to me than android:onClick.

This becomes even easier when migrating your activities to fragments. You can just call the click handler(previously set to android:onClick in xml) directly from each case block.

I would rather go for the click handling in code than using the onClick attribute in xml when working with fragments.

...
findViewById(R.id.button_login).setOnClickListener(clickListener);
...

OnClickListener clickListener = new OnClickListener() {
    @Override
    public void onClick(final View v) {
        switch(v.getId()) {
           case R.id.button_login:
              ...
              break;

           case R.id.button_logout:
              ...
        }
    }
}

When it comes to handling clicks in fragments, this looks simpler to me than android:onClick.

I would rather go for the click handling in code than using the onClick attribute in xml when working with fragments.

findViewById(R.id.button_login).setOnClickListener(clickListener);
...

OnClickListener clickListener = new OnClickListener() {
    @Override
    public void onClick(final View v) {
        switch(v.getId()) {
           case R.id.button_login:
              // which is supposed to be called automatically
              // in your activity, which has now changed to a fragment.
              onLoginClick(v);   
              break;

           case R.id.button_logout:
              ...
        }
    }
}

When it comes to handling clicks in fragments, this looks simpler to me than android:onClick.

This becomes even easier when migrating your activities to fragments. You can just call the click handler(previously set to android:onClick in xml) directly from each case block.

Source Link
Ron
  • 24.2k
  • 8
  • 57
  • 99
Loading