How to use findviewbyid in a Fragment .


if you see this line in a fragment's onCreateView()
return inflater.inflate(R.layout.fragment_data, container, false)

Change it with 

View view =inflater.inflate(R.layout.fragment_data,container,false)





TextView textView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view= inflater.inflate(R.layout.fragment_data, container, false);

Bundle bundle = getArguments();
if (bundle != null){

String message = bundle.getString("keyy");

textView=view.findViewById(R.id.textview1);
textView.setText(message);

}
return view;
}
}



This is because we cannot use findviewbyId in  a fragment directly .












Comments

Popular posts from this blog

React Js + React-Redux (part-2)

React Js + CSS Styling + React Router (part-1)

ViteJS (Module Bundlers, Build Tools)