フラグメントの XML で作成した ImageView 要素を参照するフラグメントに ImageView を作成しようとしています。ただし、このfindViewById
メソッドは、Activity クラスを拡張した場合にのみ機能します。Fragmentでも使用できるものはありますか?
public class TestClass extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ImageView imageView = (ImageView)findViewById(R.id.my_image);
return inflater.inflate(R.layout.testclassfragment, container, false);
}
}
メソッドには、findViewById
メソッドが未定義であることを示すエラーがあります。