PopupWindow で GridView を使用しようとしているときに問題が発生しました。私のアクティビティの onCreate メソッドで、次のように xml からグリッドビューを膨らませています。
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);
}
});
ボタンをクリックすると、GridView.onMeasure(int, int) から ClassCastException がスローされます。
誰が私が間違っているのか説明してもらえますか?