2012-11-04 1 views
6
//create inflater 
final LayoutInflater inflater = (LayoutInflater) this 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
//create popupwindow 
    PopupWindow pw=new PopupWindow(inflater.inflate(R.layout.menu, (ViewGroup)findViewById(R.layout.dictionarylist))); 

     Button Menu = (Button) findViewById(R.id.Menu); 
     Menu.setOnClickListener(new Button.OnClickListener() { 
      public void onClick(View v) { 
       pw.showAtLocation(v, Gravity.CENTER, 0, 0); 
       pw.update(0, 0, 200, 250); 
       pw.setOutsideTouchable(false); 
      } 
     }); 

Ce que je veux est d'afficher la fenêtre contextuelle lorsque je clique sur le bouton dans l'activité parente. La fenêtre contextuelle a des boutons quand on clique sur le bouton pour faire certaines fonctions.comment obtenir des entrées à partir d'une fenêtre pop-up

enter image description here

Répondre

1

Vous devez trouver la vue sur le bouton puis attribuez-lui l'auditeur comme ceci:

View pview=inflater.inflate(R.layout.menu, (ViewGroup)findViewById(R.layout.dictionarylist)); 

Button Menu = (Button) pview.findViewById(R.id.Menu); 

Menu.setOnClickListener(new Button.OnClickListener() { 
      public void onClick(View v) { 
       pw.showAtLocation(v, Gravity.CENTER, 0, 0); 
       pw.update(0, 0, 200, 250); 
       pw.setOutsideTouchable(false); 
      } 

initialiser également votre gonfleur si vous avez pas déjà comme ceci:

Inflator inflator = LayoutInflater.from(this); 
Questions connexes