So if your widgets and containers are specified in myMain.xml, then in your OnCreate() method of the Activity, then you use setContentView(R.layout.myMain).
If you want to access the elements in the XMl file, the element must have an android:id tag filled. To access the identified widget use findViewById by passing the numeric id found in the R.id.something.
XML fragment:
<ButtonFor the above to work the root element of the XML must declare the Android namespace.
android:id="@+id/button1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:text="Press"
/>
The fragment above declares a button with text "Press" for the specified size. To access the button, in this case, use findViewById(R.id.button1).
Eg.
Button btn=(Button) findViewById(R.id.button1);
btn.setOnClickListener(this);
...
...
No comments:
Post a Comment