I am new here, and new to Android Programming as well. So any help on this will be greatly appreciated.
I am running an Android App(basically the example given in developer.android.com) and customizing it, to add a navigation bar at the top which displays the screen number. The idea of the app is to let the user enter a message in the 1st screen, and display the message in the second screen. I've been able to setup a navigation bar in the 1st screen which displays(1/2), and have similarly defined a layout in the second screen's xml file which should display the navigation bar and (2/2) in it. Also, I have added a "Stop" button, which I will make use of later.
However, the problem I am facing is- the second screen displays only the message received from the user, and not the layout I want(navigation bar). I think I have correctly determined the root cause of this, to be the below code:
//Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
// Set the text view as the activity layout
setContentView(textView);
I think the setContentView() method that I've used here is displaying the message I received from the 1st activity. When I comment out this line, I get my desired formatting of the second screen by using:
setContentView(R.layout.activity_second_screen);
However, I am not able to understand fully why and how to club both the things together. It looks like the setContentView(R.layout..) doesn't work as expected when the setContentView(textView) is not commented, which is I guess, normal.
Thank You in advance.
Edit- Thank You, CodeMagic for such a prompt response. Before I try out your solution, here's the complete on create. I have some code in there which deals with a "stop" button, but am yet to implement it. So please ignore that.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second_screen);//Change-11/10 6:00 PM
Button buttonStop=(Button)findByViewId(R.id.buttonStop);//Change-11/10 6:00 PM
buttonStop.setOnClickListener(stopListener);//Change-11/10 6:00 PM
Intent intent = getIntent();
String message = intent.getStringExtra(FirstActivity.EXTRA_MESSAGE);
setContentView(R.layout.activity_second_screen);
// Create the text view - this code prints the message typed in first
//screen and displays on second screen, ignoring the xml layout of second screen
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
// Set the text view as the activity layout
setContentView(textView); //change-11/11-9:00 PM
//setContentView(R.layout.activity_second_screen);
}