Note that there are some explanatory texts on larger screens.

plurals
  1. POclick event of button not getting raised
    primarykey
    data
    text
    <p>I am trying to make something like customised quick badge with some buttons on it. I have successfully desgined it but when i am clicking on those buttons it does nothing. Can someone tell me where am i going wrong. </p> <p><strong>demo_layout.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;Button android:id="@+id/likemenu" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="30dp" android:text="Button" /&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" &gt; &lt;/TextView&gt; &lt;Button android:id="@+id/likequickaction" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="30dp" android:text="Button" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>popup_grid_layout.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" &gt; &lt;FrameLayout android:id="@+id/header2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10.0dip" android:background="@drawable/quickaction_top_frame" /&gt; &lt;ImageView android:id="@+id/arrow_up" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:src="@drawable/quickaction_arrow_up" /&gt; &lt;HorizontalScrollView android:id="@+id/scroll" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/header2" android:background="@drawable/quickaction_slider_background" android:fadingEdgeLength="0.0dip" android:paddingLeft="1.0dip" android:scrollbars="none" &gt; &lt;LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" &gt; &lt;ImageView android:layout_width="wrap_content" android:layout_height="fill_parent" android:background="@drawable/quickaction_slider_grip_left" /&gt; &lt;include android:layout_width="fill_parent" android:layout_height="wrap_content" layout="@layout/api_buttons" /&gt; &lt;ImageView android:layout_width="wrap_content" android:layout_height="fill_parent" android:background="@drawable/quickaction_slider_grip_right" /&gt; &lt;/LinearLayout&gt; &lt;/HorizontalScrollView&gt; &lt;FrameLayout android:id="@+id/footer" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/scroll" android:background="@drawable/quickaction_bottom_frame" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p><strong>api_buttons.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/horizontalScrollView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/quickaction_slider_background" &gt; &lt;TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" &gt; &lt;Button android:id="@+id/one" android:layout_height="wrap_content" android:layout_weight="1" android:minHeight="80dp" android:minWidth="80dp" android:text="One" /&gt; &lt;Button android:id="@+id/two" android:layout_height="wrap_content" android:layout_weight="1" android:minHeight="80dp" android:minWidth="80dp" android:text="Two" /&gt; &lt;Button android:id="@+id/three" android:layout_height="wrap_content" android:layout_weight="1" android:minHeight="80dp" android:minWidth="80dp" android:text="Three" /&gt; &lt;Button android:id="@+id/four" android:layout_height="wrap_content" android:layout_weight="1" android:minHeight="80dp" android:minWidth="80dp" android:text="Four" /&gt; &lt;Button android:id="@+id/five" android:layout_height="wrap_content" android:layout_weight="1" android:minHeight="80dp" android:minWidth="80dp" android:text="Five" /&gt; &lt;Button android:id="@+id/six" android:layout_height="wrap_content" android:layout_weight="1" android:minHeight="80dp" android:minWidth="80dp" android:text="Six" /&gt; &lt;/TableRow&gt; &lt;/HorizontalScrollView&gt; </code></pre> <p><strong>BetterPopupWindow.java</strong></p> <pre><code>public class BetterPopupWindow { protected final View anchor; private final PopupWindow window; private View root; private Drawable background = null; private final WindowManager windowManager; public BetterPopupWindow(View anchor) { this.anchor = anchor; this.window = new PopupWindow(anchor.getContext()); // when a touch even happens outside of the window // make the window go away this.window.setTouchInterceptor(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_OUTSIDE) { BetterPopupWindow.this.window.dismiss(); return true; } return false; } }); this.windowManager = (WindowManager) this.anchor.getContext() .getSystemService(Context.WINDOW_SERVICE); onCreate(); } protected void onCreate() { } protected void onShow() { } private void preShow() { if (this.root == null) { throw new IllegalStateException( "setContentView was not called with a view to display."); } onShow(); if (this.background == null) { this.window.setBackgroundDrawable(new BitmapDrawable()); } else { this.window.setBackgroundDrawable(this.background); } this.window.setWidth(WindowManager.LayoutParams.WRAP_CONTENT); this.window.setHeight(WindowManager.LayoutParams.WRAP_CONTENT); this.window.setTouchable(true); this.window.setFocusable(true); this.window.setOutsideTouchable(true); this.window.setContentView(this.root); } public void setBackgroundDrawable(Drawable background) { this.background = background; } public void setContentView(View root) { this.root = root; this.window.setContentView(root); } public void setContentView(int layoutResID) { LayoutInflater inflator = (LayoutInflater) this.anchor.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); this.setContentView(inflator.inflate(layoutResID, null)); } public void setOnDismissListener(PopupWindow.OnDismissListener listener) { this.window.setOnDismissListener(listener); } public void showLikePopDownMenu() { this.showLikePopDownMenu(0, 0); } public void showLikePopDownMenu(int xOffset, int yOffset) { this.preShow(); this.window.setAnimationStyle(R.style.Animations_PopDownMenu); this.window.showAsDropDown(this.anchor, xOffset, yOffset); } public void showLikeQuickAction() { this.showLikeQuickAction(0, 0); } public void showLikeQuickAction(int xOffset, int yOffset) { this.preShow(); this.window.setAnimationStyle(R.style.Animations_GrowFromBottom); int[] location = new int[2]; this.anchor.getLocationOnScreen(location); Rect anchorRect = new Rect(location[0], location[1], location[0] + this.anchor.getWidth(), location[1] + this.anchor.getHeight()); this.root.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); int rootWidth = this.root.getMeasuredWidth(); int rootHeight = this.root.getMeasuredHeight(); int screenWidth = this.windowManager.getDefaultDisplay().getWidth(); int screenHeight = this.windowManager.getDefaultDisplay().getHeight(); int xPos = ((screenWidth - rootWidth) / 2) + xOffset; int yPos = anchorRect.top - rootHeight + yOffset; // display on bottom if (rootHeight &gt; anchorRect.top) { yPos = anchorRect.bottom + yOffset; this.window.setAnimationStyle(R.style.Animations_GrowFromTop); } this.window.showAtLocation(this.anchor, Gravity.NO_GRAVITY, xPos, yPos); } public void dismiss() { this.window.dismiss(); } } </code></pre> <p><strong>LikeQuickActionDemo.java</strong></p> <pre><code>public class LikeQuickActionsDemo extends Activity { private Button likemenuButton; private Button likequickactionButton; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.demo_layout); this.likemenuButton = (Button) this.findViewById(R.id.likemenu); this.likemenuButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { DemoPopupWindow dw = new DemoPopupWindow(v); dw.showLikePopDownMenu(); } }); this.likequickactionButton = (Button) this .findViewById(R.id.likequickaction); this.likequickactionButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { DemoPopupWindow dw = new DemoPopupWindow(v); dw.showLikePopDownMenu(0, 200); } }); } private static class DemoPopupWindow extends BetterPopupWindow implements OnClickListener { public DemoPopupWindow(View anchor) { super(anchor); } protected void onCreate() { // inflate layout LayoutInflater inflater = (LayoutInflater) this.anchor.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); ViewGroup root = (ViewGroup) inflater.inflate( R.layout.popup_grid_layout, null); // setup button events for (int i = 0, icount = root.getChildCount(); i &lt; icount; i++) { View v = root.getChildAt(i); if (v instanceof TableRow) { TableRow row = (TableRow) v; for (int j = 0, jcount = row.getChildCount(); j &lt; jcount; j++) { View item = row.getChildAt(j); if (item instanceof Button) { Button b = (Button) item; b.setOnClickListener(this); } } } } // set the inflated view as what we want to display this.setContentView(root); } public void onClick(View v) { // we'll just display a simple toast on a button click Button b = (Button) v; Toast.makeText(this.anchor.getContext(), b.getText(), Toast.LENGTH_SHORT).show(); this.dismiss(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload