Friday, April 20, 2012

Quick Action in Android

Quick Action - Dialog like Twitter

The key is a little unknown class in the android.widget namespace. PopupWindow is the key. It allows you to display any arbitrary view on the screen.
It does most of the work for you it just needs a little bit of massaging to have it do exactly what you want.

For the Popdown menu look it's really just a matter of having the correct animation set. You can look at the Animation.PopDownMenu in the styles.xml
to see how it's done.

The QuickAction look is only slightly more complicated. It needs two animations, one for when it pops out of the top of a view, and one for when it pops down bellow the view. Then it's just a matter of computing where it should display. You can see that in BetterPopupWindow#showLikeQuickAction.

I have create QuickActionExample, attached with this article.

How to use
ActionItem addAction = new ActionItem();
//Accept action item
ActionItem accAction = new ActionItem();
//Upload action item
ActionItem upAction = new ActionItem();

Create quickaction instance and setup listener
final QuickAction mQuickAction  = new QuickAction(this);


//setup the action item click listener
mQuickAction.setOnActionItemClickListener(new QuickAction.OnActionItemClickListener() {
        public void onItemClick(int pos) {
        if (pos == 0) { //Add item selected
           Toast.makeText(Example1Activity.this, "Add item selected", Toast.LENGTH_SHORT).show();
        } else if (pos == 1) { //Accept item selected
           Toast.makeText(Example1Activity.this, "Accept item selected", Toast.LENGTH_SHORT).show();
        } else if (pos == 2) { //Upload item selected
           Toast.makeText(Example1Activity.this, "Upload items selected", Toast.LENGTH_SHORT).show();

Show dialog
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {;

Please refer to this given link for more information.
Reference Link:-[[]]

No comments:

Post a Comment