android - i want a popup menu when i click on my listview item -


my activity contains listview have 5 item in listview. items in listview , , want when click on first item in listview , there radio button in popup menu also

package com.example.shivnandan.fit;  import android.content.context; import android.content.intent; import android.content.res.resources; import android.os.bundle; import android.support.design.widget.floatingactionbutton; import android.support.design.widget.snackbar; import android.view.contextmenu; import android.view.layoutinflater; import android.view.view; import android.support.design.widget.navigationview; import android.support.v4.view.gravitycompat; import android.support.v4.widget.drawerlayout; import android.support.v7.app.actionbardrawertoggle; import android.support.v7.app.appcompatactivity; import android.support.v7.widget.toolbar; import android.view.menu; import android.view.menuitem; import android.view.viewgroup; import android.widget.adapterview; import android.widget.baseadapter; import android.widget.edittext; import android.widget.imageview; import android.widget.listview; import android.widget.textview; import android.widget.toast;  import java.util.arraylist;  public class mainactivity1 extends appcompatactivity         implements navigationview.onnavigationitemselectedlistener  {     listview list;     @override     protected void oncreate(bundle savedinstancestate)     {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar);         setsupportactionbar(toolbar);         getsupportactionbar().settitle("home");          floatingactionbutton fab = (floatingactionbutton) findviewbyid(r.id.fab);         fab.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                 snackbar.make(view, "replace own action", snackbar.length_long)                         .setaction("action", null).show();             }         });          drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout);         actionbardrawertoggle toggle = new actionbardrawertoggle(                 this, drawer, toolbar, r.string.navigation_drawer_open, r.string.navigation_drawer_close);         drawer.setdrawerlistener(toggle);         toggle.syncstate();          navigationview navigationview = (navigationview) findviewbyid(r.id.nav_view);         navigationview.setnavigationitemselectedlistener(this);         registerforcontextmenu(list);         list = (listview) findviewbyid(r.id.listview2);         list.setadapter(new shivvadapter(this));         list.setonitemclicklistener(new adapterview.onitemclicklistener()          {              @override             public void onitemclick(adapterview<?> parent, view view, int position, long id)              {                  if (position == 0)                 {                      toast.maketext(getapplicationcontext(), "gender selected", toast.length_short).show();                     }                 if (position == 1)                  {                      toast.maketext(getapplicationcontext(), "age selected ", toast.length_short).show();                  }                  if (position == 2)                  {                      toast.maketext(getapplicationcontext(), "height selected", toast.length_short).show();                  }                  if (position == 3)                  {                      toast.maketext(getapplicationcontext(), "weight selected", toast.length_short).show();                  }                 if (position == 4)                  {                      toast.maketext(getapplicationcontext(), "reset selected", toast.length_short).show();                  }              }         });     }      @override     public void oncreatecontextmenu(contextmenu menu, view v, contextmenu.contextmenuinfo menuinfo) {         super.oncreatecontextmenu(menu, v, menuinfo);      }      @override     public void onbackpressed()     {         drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout);         if (drawer.isdraweropen(gravitycompat.start))         {              drawer.closedrawer(gravitycompat.start);         }         else         {              super.onbackpressed();         }        }      @override     public boolean oncreateoptionsmenu(menu menu)     {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.main, menu);         return true;     }      @override     public boolean onoptionsitemselected(menuitem item)     {         // handle action bar item clicks here. action bar         // automatically handle clicks on home/up button, long         // specify parent activity in androidmanifest.xml.         int id = item.getitemid();          //noinspection simplifiableifstatement         if (id == r.id.action_settings)         {             toast.maketext(getapplicationcontext(), " setting ", toast.length_short).show();             return true;         }          if(id==r.id.change_photo)         {             toast.maketext(getapplicationcontext(),"change photo",toast.length_short).show();           }          return super.onoptionsitemselected(item);     }      @suppresswarnings("statementwithemptybody")     @override     public boolean onnavigationitemselected(menuitem item)     {         // handle navigation view item clicks here.         int id = item.getitemid();          if (id == r.id.nav_camera)         {          }         else if (id == r.id.nav_gallery)         {             intent = new intent(getapplicationcontext(),mainactivity.class);              startactivity(i);         }         else if (id == r.id.nav_slideshow)         {           }     else if (id == r.id.nav_manage)      {         }           drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout);         drawer.closedrawer(gravitycompat.start);         return true;     } } class singlerow2 {     string title;     //string description;     int  image;     singlerow2(string title )     {          this.title =title;         // this.description = description;         //this.image = image;     }  } class shivvadapter extends baseadapter {     arraylist<singlerow> list;     context context;     shivvadapter(context c)     {         context = c;         list=new arraylist<singlerow>();         resources res = c.getresources();         string[] titles=res.getstringarray(r.array.profiletitle);         // string[] descriptions=res.getstringarray(r.array.description);         int[] images = {r.drawable.one,r.drawable.two,r.drawable.three,r.drawable.two,r.drawable.two,r.drawable.two};         (int =0 ; i<5 ; i++)         {               list.add(new singlerow(titles[i],images[i]));         }        }     @override     public int getcount() {         return list.size();     }      @override     public object getitem(int i) {         return list.get(i);     }      @override     public long getitemid(int i) {         return i;     }      @override     public view getview(int i, view view, viewgroup viewgroup)     {          layoutinflater inflater =(layoutinflater) context.getsystemservice(context.layout_inflater_service);         view  row =  inflater.inflate(r.layout.single_row2,viewgroup,false);         textview title= (textview) row.findviewbyid(r.id.textview);         //  textview description= (textview) row.findviewbyid(r.id.textview2);          //imageview image= (imageview) row.findviewbyid(r.id.imageview);         singlerow temp = list.get(i);         title.settext(temp.title);         //description.settext(temp.description);         //image.setimageresource(temp.image);         return row;     }  } 

call method on item click

private void opendialogmanager() {          final charsequence[] items = {"male", "female"};          new alertdialog.builder(mactivity)                 .settitle("gender")                 .setsinglechoiceitems(items, 0, new dialoginterface.onclicklistener() {                     @override                     public void onclick(dialoginterface dialog, int which) {                          switch (which) {                              case 0:                                 utils.showtoast(mactivity, "male");                                 dialog.dismiss();                                 break;                              case 1:                                 utils.showtoast(mactivity, "female");                                 dialog.dismiss();                                 break;                         }                         dialog.dismiss();                     }                 })                 .setnegativebutton("cancel", new dialoginterface.onclicklistener() {                     @override                     public void onclick(dialoginterface dialog, int which) {                         dialog.dismiss();                     }                 })                 .show();     } 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -