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

私は、親アクティビティのボタンをクリックするとポップアップウィンドウを表示したいと思っています。ポップアップウィンドウには、ボタンをオンクリックするといくつかの機能が実行されます。ポップアップウィンドウからの入力方法

enter image description here

答えて

1

あなたはボタンのビューを検索し、それはこのようにリスナーを割り当てる必要があります:あなたはすでにこのようにいない場合は

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

はまた、あなたのインフレータを初期化:

Inflator inflator = LayoutInflater.from(this); 
関連する問題