Thursday, July 14, 2011

XML layout files

Use of other XML layout files than main.xml

  1. Create a new empty layout file. (Right click on the projekt and select "New" and "Android XML File")
    Mark resource as "Layout". Give the file a file name, in my case i use "inventory.xml".
  2. Place a button on the layout. (button01), save the file.
  3. In the onCreate event, place this code:
    ---
    super.onCreate(savedInstanceState);
    setContentView(R.layout.inventory);
    //findViewById(R.id.button1).setOnClickListener(xProduct); (example for doing something with the button)
    ---
    After this line of code you are able to access all objects in your own layout file.

No comments:

Post a Comment