Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What about putting extra from the previous activity and receive it in the activity where the pop up show, you can create a global final variable to identify which pop up will be send so basically it'll like this</p> <p>BaseID class </p> <pre><code>public class BaseID { public static final int POP_UP_1 = 1; public static final int POP_UP_2 = 2; public static final int POP_UP_3 = 3; public static final int POP_UP_4 = 4; } </code></pre> <p>then in previous activity before you start the new activity you should put an extra</p> <pre><code>Intent i = new Intent(previousactivity, popup.class); switch(condition) { case condition1: i.putExtra("popUpType",BaseID.POP_UP_1); break; case condition2: i.putExtra("popUpType",BaseID.POP_UP_2); break; case condition3: i.putExtra("popUpType",BaseID.POP_UP_3); break; case condition4: i.putExtra("popUpType",BaseID.POP_UP_4); break; } startActivity(i); </code></pre> <p>then in the pop up activity you can get the extra using getIntExtra()</p> <pre><code>private int popUpType; . . . popUpType= getIntent().getIntExtra("popUpType", 0); </code></pre> <p>then you can create a listener and switch the popUpType</p> <pre><code>private View.onClickListener mOnClickFilter = new View.OnClickListener() { @Override public void onClick(View v) { switch(popUpType) { case BaseID.POP_UP_1: //show popup 1 here break; case BaseID.POP_UP_2: //show popup 1 here break; case BaseID.POP_UP_3: //show popup 1 here break; case BaseID.POP_UP_4: //show popup 1 here break; } } }; </code></pre> <p>then you can add the listener to the button in the pop up activity in the oncreate</p> <pre><code>mButtonFilter.setOnClickListener(mOnClickFilter); </code></pre> <p>and for the setting different action in the pop up I think you can use callback(java interface) first you define the interface</p> <p>callbackPopUpButton interface</p> <pre><code>public interface callbackPopUpButton { public void onClick(); } </code></pre> <p>then you can implement it in the activity where you want to show pop up like this</p> <pre><code>private class cbPopUpButton implements callbackPopUpButton { @Override public void onClick() { switch(popUpType) { case BaseID.POP_UP_1: //action of button in pop up 1 break; case BaseID.POP_UP_2: //action of button in pop up 2 break; case BaseID.POP_UP_3: //action of button in pop up 3 break; case BaseID.POP_UP_4: //action of button in pop up 4 break; } } } </code></pre> <p>or if you want to switch based on view you can add View v in the onClick()</p> <p>after declaring the class you can create a new object and pass it to the popupmenu then calling the onclick like this</p> <pre><code>myPopupMenu1.setCallback(new cbPopUpButton ); //please create new function to pass the callback </code></pre> <p>the function and setting the callback should be like this (in myPopupMenu1 class)</p> <pre><code>private callbackPopUpButton cbPopUpButton public static void setCallback(callbackPopUpButton cbPopUpButton) { this.cbPopUpButton = cbPopUpButton; } </code></pre> <p>then you can add the action in the onclick listener of the button like this</p> <pre><code>buttonPopUp.setOnClickListener = new View.onClickListener() { @Override public void onClick(View v) { cbPopUpButton.onClick(); } }; </code></pre> <p>this code will invoke the onClick function in the cbPopUpButton class</p> <p>that's all!</p> <p>I hope you can understand my answer if you have any question about my answer feel free to ask in the comment :)</p>
    singulars
    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.
    1. VO
      singulars
      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