android spinner in recyclerView does not work properly











up vote
1
down vote

favorite












I am trying to use Spinner ( 3 dots with dropdown menu) in my recyclerView, but when I load this recyclerView function onItemSelected is called automatically and later when I press on item it is not called anymore. Here is my code in adapter:



       @Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(context, R.array.my_listing_item_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
((SaleAdapter.SalesViewHolder) holder).overflow.setAdapter(adapter);

((SaleAdapter.SalesViewHolder) holder).overflow.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(context, String.valueOf(position) + " item is selected", Toast.LENGTH_SHORT).show();
}

@Override
public void onNothingSelected(AdapterView<?> adapterView) {

}
});

}

public static class SalesViewHolder extends RecyclerView.ViewHolder {
public LinearLayout overflowLayout;
public Spinner overflow;

public SalesViewHolder(View itemView, Context context) {
super(itemView);

overflowLayout = (LinearLayout) itemView.findViewById(R.id.list_item_overflow_layout);
overflow = (Spinner) itemView.findViewById(R.id.list_item_overflow);
}
}


Here is code of View:



<LinearLayout
android:id="@+id/list_item_overflow_layout"
android:layout_width="54dp"
android:layout_height="54dp"
android:layout_gravity="center_vertical"
android:orientation="vertical"
android:padding="15dp"
android:background="@drawable/ic_more_vert_24dp_grey"
>

<Spinner
android:id="@+id/list_item_overflow"
android:layout_width="24dp"
android:layout_height="24dp"
/>


</LinearLayout>


Does anyone know what is the problem here with my code? Should I export setOnItemSelectedListener somewhere else?










share|improve this question






















  • So each item in the recyclerview includes a spinner which wants to mimic the menu dropdown?
    – Skemelio
    Nov 7 at 14:19










  • Tomas, yes, you are right
    – Tomas Maksimavicius
    Nov 7 at 14:43










  • I believe it's a better idea to implement a pop up menu for every recyclerview item instead of a spinner.
    – Skemelio
    Nov 7 at 14:48










  • As the docs say "Providing a drop-down similar to Spinner that does not retain a persistent selection."
    – Skemelio
    Nov 7 at 14:49










  • Tomas, but popup menu requires clear coordinates for each item, it is not possible in recycler view. Maybe do you know any examples of popup menu which does not require?
    – Tomas Maksimavicius
    Nov 7 at 14:52















up vote
1
down vote

favorite












I am trying to use Spinner ( 3 dots with dropdown menu) in my recyclerView, but when I load this recyclerView function onItemSelected is called automatically and later when I press on item it is not called anymore. Here is my code in adapter:



       @Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(context, R.array.my_listing_item_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
((SaleAdapter.SalesViewHolder) holder).overflow.setAdapter(adapter);

((SaleAdapter.SalesViewHolder) holder).overflow.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(context, String.valueOf(position) + " item is selected", Toast.LENGTH_SHORT).show();
}

@Override
public void onNothingSelected(AdapterView<?> adapterView) {

}
});

}

public static class SalesViewHolder extends RecyclerView.ViewHolder {
public LinearLayout overflowLayout;
public Spinner overflow;

public SalesViewHolder(View itemView, Context context) {
super(itemView);

overflowLayout = (LinearLayout) itemView.findViewById(R.id.list_item_overflow_layout);
overflow = (Spinner) itemView.findViewById(R.id.list_item_overflow);
}
}


Here is code of View:



<LinearLayout
android:id="@+id/list_item_overflow_layout"
android:layout_width="54dp"
android:layout_height="54dp"
android:layout_gravity="center_vertical"
android:orientation="vertical"
android:padding="15dp"
android:background="@drawable/ic_more_vert_24dp_grey"
>

<Spinner
android:id="@+id/list_item_overflow"
android:layout_width="24dp"
android:layout_height="24dp"
/>


</LinearLayout>


Does anyone know what is the problem here with my code? Should I export setOnItemSelectedListener somewhere else?










share|improve this question






















  • So each item in the recyclerview includes a spinner which wants to mimic the menu dropdown?
    – Skemelio
    Nov 7 at 14:19










  • Tomas, yes, you are right
    – Tomas Maksimavicius
    Nov 7 at 14:43










  • I believe it's a better idea to implement a pop up menu for every recyclerview item instead of a spinner.
    – Skemelio
    Nov 7 at 14:48










  • As the docs say "Providing a drop-down similar to Spinner that does not retain a persistent selection."
    – Skemelio
    Nov 7 at 14:49










  • Tomas, but popup menu requires clear coordinates for each item, it is not possible in recycler view. Maybe do you know any examples of popup menu which does not require?
    – Tomas Maksimavicius
    Nov 7 at 14:52













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am trying to use Spinner ( 3 dots with dropdown menu) in my recyclerView, but when I load this recyclerView function onItemSelected is called automatically and later when I press on item it is not called anymore. Here is my code in adapter:



       @Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(context, R.array.my_listing_item_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
((SaleAdapter.SalesViewHolder) holder).overflow.setAdapter(adapter);

((SaleAdapter.SalesViewHolder) holder).overflow.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(context, String.valueOf(position) + " item is selected", Toast.LENGTH_SHORT).show();
}

@Override
public void onNothingSelected(AdapterView<?> adapterView) {

}
});

}

public static class SalesViewHolder extends RecyclerView.ViewHolder {
public LinearLayout overflowLayout;
public Spinner overflow;

public SalesViewHolder(View itemView, Context context) {
super(itemView);

overflowLayout = (LinearLayout) itemView.findViewById(R.id.list_item_overflow_layout);
overflow = (Spinner) itemView.findViewById(R.id.list_item_overflow);
}
}


Here is code of View:



<LinearLayout
android:id="@+id/list_item_overflow_layout"
android:layout_width="54dp"
android:layout_height="54dp"
android:layout_gravity="center_vertical"
android:orientation="vertical"
android:padding="15dp"
android:background="@drawable/ic_more_vert_24dp_grey"
>

<Spinner
android:id="@+id/list_item_overflow"
android:layout_width="24dp"
android:layout_height="24dp"
/>


</LinearLayout>


Does anyone know what is the problem here with my code? Should I export setOnItemSelectedListener somewhere else?










share|improve this question













I am trying to use Spinner ( 3 dots with dropdown menu) in my recyclerView, but when I load this recyclerView function onItemSelected is called automatically and later when I press on item it is not called anymore. Here is my code in adapter:



       @Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(context, R.array.my_listing_item_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
((SaleAdapter.SalesViewHolder) holder).overflow.setAdapter(adapter);

((SaleAdapter.SalesViewHolder) holder).overflow.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(context, String.valueOf(position) + " item is selected", Toast.LENGTH_SHORT).show();
}

@Override
public void onNothingSelected(AdapterView<?> adapterView) {

}
});

}

public static class SalesViewHolder extends RecyclerView.ViewHolder {
public LinearLayout overflowLayout;
public Spinner overflow;

public SalesViewHolder(View itemView, Context context) {
super(itemView);

overflowLayout = (LinearLayout) itemView.findViewById(R.id.list_item_overflow_layout);
overflow = (Spinner) itemView.findViewById(R.id.list_item_overflow);
}
}


Here is code of View:



<LinearLayout
android:id="@+id/list_item_overflow_layout"
android:layout_width="54dp"
android:layout_height="54dp"
android:layout_gravity="center_vertical"
android:orientation="vertical"
android:padding="15dp"
android:background="@drawable/ic_more_vert_24dp_grey"
>

<Spinner
android:id="@+id/list_item_overflow"
android:layout_width="24dp"
android:layout_height="24dp"
/>


</LinearLayout>


Does anyone know what is the problem here with my code? Should I export setOnItemSelectedListener somewhere else?







android android-recyclerview spinner adapter






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 7 at 13:43









Tomas Maksimavicius

11210




11210












  • So each item in the recyclerview includes a spinner which wants to mimic the menu dropdown?
    – Skemelio
    Nov 7 at 14:19










  • Tomas, yes, you are right
    – Tomas Maksimavicius
    Nov 7 at 14:43










  • I believe it's a better idea to implement a pop up menu for every recyclerview item instead of a spinner.
    – Skemelio
    Nov 7 at 14:48










  • As the docs say "Providing a drop-down similar to Spinner that does not retain a persistent selection."
    – Skemelio
    Nov 7 at 14:49










  • Tomas, but popup menu requires clear coordinates for each item, it is not possible in recycler view. Maybe do you know any examples of popup menu which does not require?
    – Tomas Maksimavicius
    Nov 7 at 14:52


















  • So each item in the recyclerview includes a spinner which wants to mimic the menu dropdown?
    – Skemelio
    Nov 7 at 14:19










  • Tomas, yes, you are right
    – Tomas Maksimavicius
    Nov 7 at 14:43










  • I believe it's a better idea to implement a pop up menu for every recyclerview item instead of a spinner.
    – Skemelio
    Nov 7 at 14:48










  • As the docs say "Providing a drop-down similar to Spinner that does not retain a persistent selection."
    – Skemelio
    Nov 7 at 14:49










  • Tomas, but popup menu requires clear coordinates for each item, it is not possible in recycler view. Maybe do you know any examples of popup menu which does not require?
    – Tomas Maksimavicius
    Nov 7 at 14:52
















So each item in the recyclerview includes a spinner which wants to mimic the menu dropdown?
– Skemelio
Nov 7 at 14:19




So each item in the recyclerview includes a spinner which wants to mimic the menu dropdown?
– Skemelio
Nov 7 at 14:19












Tomas, yes, you are right
– Tomas Maksimavicius
Nov 7 at 14:43




Tomas, yes, you are right
– Tomas Maksimavicius
Nov 7 at 14:43












I believe it's a better idea to implement a pop up menu for every recyclerview item instead of a spinner.
– Skemelio
Nov 7 at 14:48




I believe it's a better idea to implement a pop up menu for every recyclerview item instead of a spinner.
– Skemelio
Nov 7 at 14:48












As the docs say "Providing a drop-down similar to Spinner that does not retain a persistent selection."
– Skemelio
Nov 7 at 14:49




As the docs say "Providing a drop-down similar to Spinner that does not retain a persistent selection."
– Skemelio
Nov 7 at 14:49












Tomas, but popup menu requires clear coordinates for each item, it is not possible in recycler view. Maybe do you know any examples of popup menu which does not require?
– Tomas Maksimavicius
Nov 7 at 14:52




Tomas, but popup menu requires clear coordinates for each item, it is not possible in recycler view. Maybe do you know any examples of popup menu which does not require?
– Tomas Maksimavicius
Nov 7 at 14:52












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Better use a PopUpMenu for each item in the list. Have an ImageView instead of the Spinner which will display a "3 dot" icon. When someone clicks the dots the PopUpMenu will... pop up!



In steps:



1)Replace the Spinner in the xml layout with an ImageView which will display the three dots icon.



2) Define a listener class inside your RecyclerView.Adapter<SalesViewHolder> and save an instance there.



3) Inside SalesViewHolder set an OnClickListener to responds to clicks.



4) Pop up from the Activity.



Your new adapter should look something like this



class SalesAdapter extends RecyclerView.Adapter<SalesViewHolder>{
public interface OnMenuItemClickListener{
void onMenuItemClicked(ImageView view);
}

private OnMenuItemClickListener listener;

public void setOnMenuItemClickListener(OnMenuItemClickListener listener){
this.listener = listener;
}

public static class SalesViewHolder extends RecyclerView.ViewHolder {
public LinearLayout overflowLayout;
public ImageView menu;

public SalesViewHolder(View itemView, Context context) {
super(itemView);

overflowLayout = (LinearLayout) itemView.findViewById(R.id.list_item_overflow_layout);
menu= (ImageView) itemView.findViewById(R.id.imageview_id);
// Make sure to enable lambdas
menu.setOnClickListener( (view) -> {
if( listener != null ){
listener.onMenuItemClicked(view);
}
}
}
}

}


Your activity must implement the OnMenuItemClickListener and may look something like this



class YourActivity extends Activity implements SalesAdapter.OnMenuItemClickListener{

// Don't forget to set the listener to the adapter, let's suppose that happens in onCreate()
@Override
public void onCreate(Bundle arg){
SalesAdapter adapter = new SalesAdapter();
adapter.setOnMenuItemClickListener(this);
}

@Override
public void onMenuItemClicked(ImageView menu){
showPopUp(menu);
}

private void showPopup(View v) {
PopupMenu popup = new PopupMenu(this, v);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.actions, popup.getMenu());
popup.show();
}

}


Don't forget to supply menu actions etc... as mentioned here.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53190683%2fandroid-spinner-in-recyclerview-does-not-work-properly%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    Better use a PopUpMenu for each item in the list. Have an ImageView instead of the Spinner which will display a "3 dot" icon. When someone clicks the dots the PopUpMenu will... pop up!



    In steps:



    1)Replace the Spinner in the xml layout with an ImageView which will display the three dots icon.



    2) Define a listener class inside your RecyclerView.Adapter<SalesViewHolder> and save an instance there.



    3) Inside SalesViewHolder set an OnClickListener to responds to clicks.



    4) Pop up from the Activity.



    Your new adapter should look something like this



    class SalesAdapter extends RecyclerView.Adapter<SalesViewHolder>{
    public interface OnMenuItemClickListener{
    void onMenuItemClicked(ImageView view);
    }

    private OnMenuItemClickListener listener;

    public void setOnMenuItemClickListener(OnMenuItemClickListener listener){
    this.listener = listener;
    }

    public static class SalesViewHolder extends RecyclerView.ViewHolder {
    public LinearLayout overflowLayout;
    public ImageView menu;

    public SalesViewHolder(View itemView, Context context) {
    super(itemView);

    overflowLayout = (LinearLayout) itemView.findViewById(R.id.list_item_overflow_layout);
    menu= (ImageView) itemView.findViewById(R.id.imageview_id);
    // Make sure to enable lambdas
    menu.setOnClickListener( (view) -> {
    if( listener != null ){
    listener.onMenuItemClicked(view);
    }
    }
    }
    }

    }


    Your activity must implement the OnMenuItemClickListener and may look something like this



    class YourActivity extends Activity implements SalesAdapter.OnMenuItemClickListener{

    // Don't forget to set the listener to the adapter, let's suppose that happens in onCreate()
    @Override
    public void onCreate(Bundle arg){
    SalesAdapter adapter = new SalesAdapter();
    adapter.setOnMenuItemClickListener(this);
    }

    @Override
    public void onMenuItemClicked(ImageView menu){
    showPopUp(menu);
    }

    private void showPopup(View v) {
    PopupMenu popup = new PopupMenu(this, v);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.actions, popup.getMenu());
    popup.show();
    }

    }


    Don't forget to supply menu actions etc... as mentioned here.






    share|improve this answer

























      up vote
      1
      down vote



      accepted










      Better use a PopUpMenu for each item in the list. Have an ImageView instead of the Spinner which will display a "3 dot" icon. When someone clicks the dots the PopUpMenu will... pop up!



      In steps:



      1)Replace the Spinner in the xml layout with an ImageView which will display the three dots icon.



      2) Define a listener class inside your RecyclerView.Adapter<SalesViewHolder> and save an instance there.



      3) Inside SalesViewHolder set an OnClickListener to responds to clicks.



      4) Pop up from the Activity.



      Your new adapter should look something like this



      class SalesAdapter extends RecyclerView.Adapter<SalesViewHolder>{
      public interface OnMenuItemClickListener{
      void onMenuItemClicked(ImageView view);
      }

      private OnMenuItemClickListener listener;

      public void setOnMenuItemClickListener(OnMenuItemClickListener listener){
      this.listener = listener;
      }

      public static class SalesViewHolder extends RecyclerView.ViewHolder {
      public LinearLayout overflowLayout;
      public ImageView menu;

      public SalesViewHolder(View itemView, Context context) {
      super(itemView);

      overflowLayout = (LinearLayout) itemView.findViewById(R.id.list_item_overflow_layout);
      menu= (ImageView) itemView.findViewById(R.id.imageview_id);
      // Make sure to enable lambdas
      menu.setOnClickListener( (view) -> {
      if( listener != null ){
      listener.onMenuItemClicked(view);
      }
      }
      }
      }

      }


      Your activity must implement the OnMenuItemClickListener and may look something like this



      class YourActivity extends Activity implements SalesAdapter.OnMenuItemClickListener{

      // Don't forget to set the listener to the adapter, let's suppose that happens in onCreate()
      @Override
      public void onCreate(Bundle arg){
      SalesAdapter adapter = new SalesAdapter();
      adapter.setOnMenuItemClickListener(this);
      }

      @Override
      public void onMenuItemClicked(ImageView menu){
      showPopUp(menu);
      }

      private void showPopup(View v) {
      PopupMenu popup = new PopupMenu(this, v);
      MenuInflater inflater = popup.getMenuInflater();
      inflater.inflate(R.menu.actions, popup.getMenu());
      popup.show();
      }

      }


      Don't forget to supply menu actions etc... as mentioned here.






      share|improve this answer























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        Better use a PopUpMenu for each item in the list. Have an ImageView instead of the Spinner which will display a "3 dot" icon. When someone clicks the dots the PopUpMenu will... pop up!



        In steps:



        1)Replace the Spinner in the xml layout with an ImageView which will display the three dots icon.



        2) Define a listener class inside your RecyclerView.Adapter<SalesViewHolder> and save an instance there.



        3) Inside SalesViewHolder set an OnClickListener to responds to clicks.



        4) Pop up from the Activity.



        Your new adapter should look something like this



        class SalesAdapter extends RecyclerView.Adapter<SalesViewHolder>{
        public interface OnMenuItemClickListener{
        void onMenuItemClicked(ImageView view);
        }

        private OnMenuItemClickListener listener;

        public void setOnMenuItemClickListener(OnMenuItemClickListener listener){
        this.listener = listener;
        }

        public static class SalesViewHolder extends RecyclerView.ViewHolder {
        public LinearLayout overflowLayout;
        public ImageView menu;

        public SalesViewHolder(View itemView, Context context) {
        super(itemView);

        overflowLayout = (LinearLayout) itemView.findViewById(R.id.list_item_overflow_layout);
        menu= (ImageView) itemView.findViewById(R.id.imageview_id);
        // Make sure to enable lambdas
        menu.setOnClickListener( (view) -> {
        if( listener != null ){
        listener.onMenuItemClicked(view);
        }
        }
        }
        }

        }


        Your activity must implement the OnMenuItemClickListener and may look something like this



        class YourActivity extends Activity implements SalesAdapter.OnMenuItemClickListener{

        // Don't forget to set the listener to the adapter, let's suppose that happens in onCreate()
        @Override
        public void onCreate(Bundle arg){
        SalesAdapter adapter = new SalesAdapter();
        adapter.setOnMenuItemClickListener(this);
        }

        @Override
        public void onMenuItemClicked(ImageView menu){
        showPopUp(menu);
        }

        private void showPopup(View v) {
        PopupMenu popup = new PopupMenu(this, v);
        MenuInflater inflater = popup.getMenuInflater();
        inflater.inflate(R.menu.actions, popup.getMenu());
        popup.show();
        }

        }


        Don't forget to supply menu actions etc... as mentioned here.






        share|improve this answer












        Better use a PopUpMenu for each item in the list. Have an ImageView instead of the Spinner which will display a "3 dot" icon. When someone clicks the dots the PopUpMenu will... pop up!



        In steps:



        1)Replace the Spinner in the xml layout with an ImageView which will display the three dots icon.



        2) Define a listener class inside your RecyclerView.Adapter<SalesViewHolder> and save an instance there.



        3) Inside SalesViewHolder set an OnClickListener to responds to clicks.



        4) Pop up from the Activity.



        Your new adapter should look something like this



        class SalesAdapter extends RecyclerView.Adapter<SalesViewHolder>{
        public interface OnMenuItemClickListener{
        void onMenuItemClicked(ImageView view);
        }

        private OnMenuItemClickListener listener;

        public void setOnMenuItemClickListener(OnMenuItemClickListener listener){
        this.listener = listener;
        }

        public static class SalesViewHolder extends RecyclerView.ViewHolder {
        public LinearLayout overflowLayout;
        public ImageView menu;

        public SalesViewHolder(View itemView, Context context) {
        super(itemView);

        overflowLayout = (LinearLayout) itemView.findViewById(R.id.list_item_overflow_layout);
        menu= (ImageView) itemView.findViewById(R.id.imageview_id);
        // Make sure to enable lambdas
        menu.setOnClickListener( (view) -> {
        if( listener != null ){
        listener.onMenuItemClicked(view);
        }
        }
        }
        }

        }


        Your activity must implement the OnMenuItemClickListener and may look something like this



        class YourActivity extends Activity implements SalesAdapter.OnMenuItemClickListener{

        // Don't forget to set the listener to the adapter, let's suppose that happens in onCreate()
        @Override
        public void onCreate(Bundle arg){
        SalesAdapter adapter = new SalesAdapter();
        adapter.setOnMenuItemClickListener(this);
        }

        @Override
        public void onMenuItemClicked(ImageView menu){
        showPopUp(menu);
        }

        private void showPopup(View v) {
        PopupMenu popup = new PopupMenu(this, v);
        MenuInflater inflater = popup.getMenuInflater();
        inflater.inflate(R.menu.actions, popup.getMenu());
        popup.show();
        }

        }


        Don't forget to supply menu actions etc... as mentioned here.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 7 at 16:30









        Skemelio

        36612




        36612






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53190683%2fandroid-spinner-in-recyclerview-does-not-work-properly%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud

            Zucchini