Reputation: 1
Here's the code:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
String message = "Email: \n" +intent.getStringExtra(MainActivity.ACCOUNT_EMAIL);
setContentView(R.layout.activity_display_message);
TextView textView = (TextView) findViewById(R.id.display_info);
//textView.setText(message);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_display_message,
container, false);
return rootView;
}
}
The ID name in the XML is definitely right, but for whatever reason this commented line always returns null. When I have the line commented the fragment opens with the text view there (i have some placeholder text). I can't access this thing from the code.
Upvotes: 0
Views: 136
Reputation: 38252
You say that the fragment displays with the TextView, but you're attempting to reference the TextView from your Activity (and the Activity's layout).
Without seeing the layouts, I'm guessing the TextView is in fragment_display_message.xml
(and not activity_display_message.xml
).
It seems that you want to move the logic of accessing the TextView into your Fragment's onCreateView()
. Bear in mind that you may want to use Fragment arguments to set the message as obtaining it directly from the Activity's intent will no longer work.
Upvotes: 1