Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not Actually an Issue but an Enhancements #36

Open
crashenburne opened this issue Aug 14, 2011 · 0 comments
Open

Not Actually an Issue but an Enhancements #36

crashenburne opened this issue Aug 14, 2011 · 0 comments

Comments

@crashenburne
Copy link

First of all a big thanks to your component. I am currently developing my first android app with the help of your component.

I have added some enhancements and if you don't mind, you can review and probably add them

  1. Added home click listener

    public void setOnHomeClickListener(OnClickListener listener) {
    mHomeBtn.setOnClickListener(listener);
    }

  2. Added Action listener - a copy of your removeAction but this one is overriding the listener

    public void setActionOnClickListener(Action action, OnClickListener listener) {
    int childCount = mActionsView.getChildCount();
    for (int i = 0; i < childCount; i++) {
    View view = mActionsView.getChildAt(i);
    if (view != null) {
    final Object tag = view.getTag();
    if (tag instanceof Action && tag.equals(action)) {
    v.setOnClickListener(listener);
    }
    }
    }
    }

Example implementation

The setHomeOnClickListener will intercept the action before proceeding. Basically it will just validate if you want to discard changes made on the create screen.

    actionBar.setOnHomeClickListener(new OnClickListener() {        
        @Override
        public void onClick(final View v) {
            // TODO Auto-generated method stub
            AlertDialog.Builder builder = new AlertDialog.Builder(CreateActivity.this);
            builder.setMessage("Discard changes?")
               .setCancelable(false)
               .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       actionBar.onClick(v);       
                       CreateActivity.this.finish();                            
                   }
               })
               .setNegativeButton("No", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                   }
               });

            AlertDialog alert = builder.create();
            alert.show();
        }
    }) ;

The setActionOnClickListener will intercept the action by first saving the data before proceding with the request.

    actionBar.setActionOnClickListener(saveAction, new OnClickListener() {          
        @Override
        public void onClick(View v) {
            //save data
            actionBar.onClick(v);
        }
    });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant