gpt4 book ai didi

android - 带有 GridView 的 PopupWindow - 展开 View 时出现问题

转载 作者:行者123 更新时间:2023-11-30 04:53:28 25 4
gpt4 key购买 nike

我在尝试使用 GridView 时遇到问题弹出窗口。在我的 Activity 的 onCreate 方法中,我正在膨胀一个来自 xml 的 gridview 如下:

LayoutInflater inflater = (LayoutInflater)this.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
final GridView popupview = (GridView) inflater.inflate
(R.layout.gridviewpopup, null, false);
popupview.setAdapter(new ImageAdapter(this));

希望此 GridView 在单击按钮时弹出。也在里面我的 Activity onCreate,我有:

final Button addButton = (Button) findViewById(R.id.add);
addButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
PopupWindow mwindow = new PopupWindow(popupview, 100, 100);
mwindow.showAtLocation(findViewById(R.id.main), Gravity.CENTER, 100, 100);
mwindow.setFocusable(true);
}
});

单击按钮时,我从GridView.onMeasure(int, int).

任何人都可以向我解释我做错了什么吗?

最佳答案

我最终找到了问题所在。我正在使用 ImageAdapter 代码形成 Hello, Gallery 示例。其中包含一行代码引用图库:

imageView.setLayoutParams(new Gallery.LayoutParams(150, 120));

当与 GridView 一起使用时,这显然会导致类转换异常。

现在我的 GridView 在弹出窗口中正确显示了,我无法捕获 OnItemClick 事件。下面是我的代码。当我在我的中进行选择时,永远不会调用 OnItemClick弹出窗口中的 GridView 。有什么想法吗?

final GridView gView = (GridView) grid_layout.findViewById
(R.id.gridview_layout);
gView.setWillNotDraw(false);
gView.setFocusableInTouchMode(true);
gView.setClickable(true);
gView.setAdapter(new ImageAdapter(this));

final PopupWindow soundSelectorWindow = new PopupWindow(this);
soundSelectorWindow.setContentView(grid_layout);
soundSelectorWindow.setBackgroundDrawable(new BitmapDrawable());
soundSelectorWindow.setOutsideTouchable(false);
soundSelectorWindow.setTouchable(true);

gView.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView parent, View v, int position,
long id)
{
//Never gets here.
soundSelectorWindow.dismiss();
}
});

关于android - 带有 GridView 的 PopupWindow - 展开 View 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1718748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com