I am new-bee to android.
Here is my xml file -
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="@+id/linearlayout"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:id="@+id/textview" />
</LinearLayout>
and Very basic code -
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View view=getLayoutInflater().inflate(R.layout.activity_main,null);
//setContentView(view);
LinearLayout ly = (LinearLayout)findViewById(R.id.linearlayout);
Log.i("System.out ","linear layout = " + view);
Log.i("System.out ","linear layout = " + ly);
}
Output:
05-10 11:44:15.996: I/System.out(6494): linear layout = android.widget.LinearLayout@41e34db8
05-10 11:44:15.996: I/System.out(6494): linear layout = null
findViewById()
is returning null? Why?
If I uncomment setContentView(view)
and run again ..
Output:
05-10 11:50:12.781: I/System.out(7791): linear layout = android.widget.LinearLayout@41e0d6c8
05-10 11:50:12.781: I/System.out(7791): linear layout = android.widget.LinearLayout@41e0d6c8
What extra does setContentView()
is doing?