當前位置:編程學習大全網 - 源碼下載 - android 想在popupwindow中顯示gridview,怎麽辦啊?

android 想在popupwindow中顯示gridview,怎麽辦啊?

private void openPopupwin() {

LayoutInflater mLayoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);

ViewGroup menuView = (ViewGroup) mLayoutInflater.inflate(

R.layout.gridview_pop, null, true);

menuGrid = (GridView) menuView.findViewById(R.id.gridview);

menuGrid.setAdapter(getMenuAdapter(menu_name_array, menu_image_array));

menuGrid.requestFocus();

menuGrid.setOnItemClickListener(new OnItemClickListener() {

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,

long arg3) {

if (arg2 == 11) {

popupWindow.dismiss();

}

}

});

menuGrid.setOnKeyListener(new OnKeyListener() {// 焦點到了gridview上,所以需要監聽此處的鍵盤事件。否則會出現不響應鍵盤事件的情況

public boolean onKey(View v, int keyCode, KeyEvent event) {

switch (keyCode) {

case KeyEvent.KEYCODE_MENU:

if (popupWindow != null && popupWindow.isShowing()) {

popupWindow.dismiss();

}

break;

}

System.out.println("menuGridfdsfdsfdfd");

return true;

}

});

popupWindow = new PopupWindow(menuView, LayoutParams.FILL_PARENT,

LayoutParams.FILL_PARENT, true);

popupWindow.setBackgroundDrawable(new BitmapDrawable());

popupWindow.setAnimationStyle(R.style.PopupAnimation);

popupWindow.showAtLocation(findViewById(R.id.parent), Gravity.CENTER

| Gravity.CENTER, 0, 0);

popupWindow.update();

}

  • 上一篇:2000-3000價位段的手機推薦?
  • 下一篇:研究實踐:研究的三步七步2022-02-14
  • copyright 2024編程學習大全網