How Do I Access Items ~Built~ In xml?

This is a discussion on How Do I Access Items ~Built~ In xml? within the Beginning Developers forums, part of the Android Development category; Just started java programming, because of Android. Just started Android programming. How do I access items built in xml? I am using the hello example ...

Results 1 to 2 of 2

Thread: How Do I Access Items ~Built~ In xml?

  1. #1
    Android Lurker androidkeep's Avatar
    Join Date
    Apr 2012
    Posts
    1

    How Do I Access Items ~Built~ In xml?

    Just started java programming, because of Android. Just started Android programming.
    How do I access items built in xml?
    I am using the hello example that came with the SDK
    Here is my HelloAndroid.java:
    ------------
    Code:
    package com.example.helloandroid;
    import android.app.Activity;
    import android.os.Bundle;
    public class HelloAndroid extends Activity {
      /** Called when the activity is first created. */
        @Override
            
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);}
    }
    ------------
    I have some checkboxes I want access to
    In PACKAGE EXPLORER under:
    res->layout->main.xml
    I have the IU; I changed the layout to a table layout
    -------------
    ...
    Code:
    <TableRow>    
        <CheckBox
            android:id="@+id/checkbox01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:onClick="onCheckboxClicked"
            android:text="@string/Lt"/>
    ...
    -------------
    the program works / compiles; and runs on a phone. but it is just a Face - no code / action.
    When I try to access the checkbox from within HelloAndroid.java, it does not know of a ~checkbox01~ "...can not be resolved to a type".
    So, How do I access items built in xml?
    Where does the meat / code in a Android program go?
    In a Package or Class?
    And how does one make certain that these Ps or Cs know about the XML objects?

  2. Android.net is the premier Android Forum. Registered users do not see these ads. .

  3. #2
    Android Lurker Orby's Avatar
    Join Date
    May 2012
    Posts
    4
    Hi,

    You need to create a new Checkbox object and then play with it... for example... in your OnCreate:

    Code:
    Checkbox mycheck = (CheckBox) findViewById(R.id.checkbox01);
    Basically find the view using the id, which in this case is "checkbox01" and override View to CheckBox to make it work.

    BR,
    Orby

Remove Ads

http://www.scramblerducati.org/

Sponsored Links

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Similar Threads

  1. Replies: 0
    Last Post: 03-18-2012, 07:57 AM
  2. Replies: 0
    Last Post: 11-16-2011, 01:40 PM
  3. Android tablets built into Indian buses
    By wicked in forum Android News
    Replies: 1
    Last Post: 02-11-2011, 07:54 PM
  4. How To: Transfer Items Via Bluetooth
    By DisneyRicky in forum Android Forum
    Replies: 1
    Last Post: 02-08-2011, 05:18 PM
  5. Replies: 6
    Last Post: 10-31-2010, 02:38 AM

Search tags for this page

android access url xml main thread

,

android code for built in xml

Click on a term to search our sites for related topics.
Android Forum