带有 GridView 的 PopupWindow - 膨胀视图的问题
我在尝试在 GridView 中使用 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 在单击按钮时弹出。还有里面的 我的活动是 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);
}
});
单击按钮时,我抛出 ClassCastException GridView.onMeasure(int, int)。
谁能向我解释一下我做错了什么?
I am having an issue while trying to use a GridView in a
PopupWindow. On my Activity's onCreate method, I am inflating a
gridview from xml as follows:
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));
would like this GridView to popup on a button click. Also inside of
my activity's onCreate, I have:
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);
}
});
On button click, I am throwing a ClassCastException from
GridView.onMeasure(int, int).
Can anyone please explain to me what I am doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终找到了问题所在。我正在使用 ImageAdapter 代码
形成“你好,画廊”示例。其中包含一行代码
引用 Gallary:
与 GridView 一起使用时,这显然会导致类转换
例外。
现在我的 GridView 在弹出窗口中正确显示,我
捕获 OnItemClick 事件时遇到问题。下面是我的代码。
当我在我的中进行选择时,OnItemClick 永远不会被调用
弹出窗口中的 gridview。有什么想法吗?
I ended up finding the problem. I was using the ImageAdapter code
form the Hello, Gallery example. That contained a line of code
referencing a Gallary:
When used with a GridView, this obviously causes a class cast
exception.
Now that I have my GridView displaying properly in a popupwindow, I am
having trouble capturing the OnItemClick event. Below is my code.
OnItemClick is never being called when I make a selection in my
gridview in the popupwindow. Any ideas?