Aklımda Kalası Kelimeler

* давайте работать вместе
* Zarf ve Mazruf, Zerafet(xHoyratlık) ile aynı kökten(za-ra-fe) gelir
* Bedesten
* Suç subuta ermiştir - Suç sabit olmuştur

27 Mayıs 2011 Cuma

Neden android'de + işaretini id nin önüne koyarız?



@+id/degiskenAdi
uygulamanın namespace inde "degiskenAdi" isimli bir "id" oluşturuyorsun demektir.

Bu durumda degiskenAdi uygulamada R.java dosyasına eklenecek.

Artık @id/degiskenAdi diyerek erişebilirsin.
Her ID nin bir integer değere karşılık geldiğini ama objenin bulunduğu layoutun xml'inde string olarak belirtilir.

@android:id/degiskenAdi
android isim uzayında (namespace) tanımlı degiskenAdi'nı işaret ediyorsun demektir(Android resource ID) ve + kullanman gerekmez. Android resource ID ye ulaşmak için kesinlikle "@android:" ile başlaman gerekir.

android:*** Android framework'ündeki *** diye tanımlı şeye referans verdiğini gösterir.




ID

http://developer.android.com/guide/topics/ui/declaring-layout.html

Any View object may have an integer ID associated with it, to uniquely identify the View within the tree. When the application is compiled, this ID is referenced as an integer, but the ID is typically assigned in the layout XML file as a string, in the id attribute. This is an XML attribute common to all View objects (defined by the View class) and you will use it very often. The syntax for an ID, inside an XML tag is:

android:id="@+id/my_button"

The at-symbol (@) at the beginning of the string indicates that the XML parser should parse and expand the rest of the ID string and identify it as an ID resource. The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in the R.java file). There are a number of other ID resources that are offered by the Android framework. When referencing an Android resource ID, you do not need the plus-symbol, but must add the android package namespace, like so:

android:id="@android:id/empty"

With the android package namespace in place, we're now referencing an ID from the android.R resources class, rather than the local resources class.

In order to create views and reference them from the application, a common pattern is to:

1. Define a view/widget in the layout file and assign it a unique ID:

<button id="@+id/my_button" layout_width="wrap_content" layout_height="wrap_content" text="@string/my_button_text">

2. Then create an instance of the view object and capture it from the layout (typically in the onCreate() method):

Button myButton = (Button) findViewById(R.id.my_button);

Defining IDs for view objects is important when creating a RelativeLayout. In a relative layout, sibling views can define their layout relative to another sibling view, which is referenced by the unique ID.

An ID need not be unique throughout the entire tree, but it should be unique within the part of the tree you are searching (which may often be the entire tree, so it's best to be completely unique when possible).

Hiç yorum yok: