В моем Fragment
есть TextureView
, и Фрагмент должен заново наполнить макет.Я использую Camera
API в Activity
(PS: Camera API должен вызываться в Activity), и я могу использовать SurfaceTexture
для получения предварительного просмотра камеры.
Вопрос, как сделать так, чтобы TextureView мог получить предварительный просмотр камеры.Я устал от многих решений, но все они получили нулевую ссылку на объект.
public class MyFragment extends PresentationFragment{
private TextureView textureView;
private TextView textView;
public View onCreateView(LayoutInflater layoutInflater, @Nullable ViewGroup contatiner, Bundle savedInstanceState) {
rootView = layoutInflater.inflate(R.layout.external_display, contatiner, false);
textureView = rootView.findViewById(R.id.camera_view);
textView = rootView.findViewById(R.id.test_text);
return rootView;
}
}
В Activity:
private MyFragment myFragment;
private TextureView textureView;
private SurfaceTexture surfaceTexture;
В onCreate:
myFragment =(myFragment)getFragmentManager().findFragmentById(R.id.external_display);
View view = myFragment.getView();
textureView = view.findViewById(R.id.camera_preview);
surfaceTexture = textureView.getSurfaceTexture();
getView () nullссылка на объект.