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

Điều tôi muốn hiển thị cửa sổ bật lên khi tôi nhấp vào nút trong hoạt động gốc. Cửa sổ bật lên có các nút khi nhấn vào nút, nó thực hiện một số chức năng.cách nhận dữ liệu nhập từ cửa sổ bật lên

enter image description here

Trả lời

1

Bạn phải tìm quan điểm của các nút và sau đó gán người nghe đến nó như thế này:

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

Cũng khởi inflator của bạn nếu bạn chưa sẵn sàng như thế này:

Inflator inflator = LayoutInflater.from(this); 
Các vấn đề liên quan