I have a fragment that I need to display on the screen. I want to be able to use InjectView
to inject my UI elements. InjectView works fine on activities because the view (xml) is set during onCreate
, however on fragments the view is set on onCreatView
.
So is there a way to use InjectView on fragments? I know that I could use findViewbyId to find each element, but I rather use InjectView
public class ProfileFragment extends RoboDialogFragment {
@InjectView(R.id.commentEditText)
protected EditText commentEditText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// I get a null pointer exception here
commentEditText.setText("Some comment");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.profile , container, false);
// I get a null pointer exception here
commentEditText.setText("Some comment");
return view;
}
}
Apple and Google both have fantastic app stores. But Android is far superior at organizing apps, letting you put important stuff on the home screens and hide less useful apps in the app drawer. Also, Android's widgets are much more useful than Apple's.
Android OS is a Linux-based mobile operating system that primarily runs on smartphones and tablets. The Android platform includes an operating system based upon the Linux kernel, a GUI, a web browser and end-user applications that can be downloaded.
The latest version of Android OS is 12, released in October 2021. Learn more about OS 12, including its key features. Older versions of Android include: Tiramisu (OS 13)
Android Inc., was bought by the American search engine company Google Inc., in 2005. At Google, the Android team decided to base their project on Linux, an open source operating system for personal computers.
Injection happens during onViewCreated
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
commentEditText.setText("Some comment");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With