2012-11-04 13 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); 
      } 
     }); 

Quello che voglio è mostrare la finestra popup quando faccio clic sul pulsante nell'attività padre. La finestra popup ha pulsanti quando onclick il pulsante esegue alcune funzioni.come ottenere input da una finestra pop-up

enter image description here

risposta

1

dovete trovare la vista del pulsante e quindi assegnare l'ascoltatore in questo modo:

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); 
      } 

inizializzare anche il vostro gonfiaggio se non l'hai già in questo modo:

Inflator inflator = LayoutInflater.from(this); 
Problemi correlati