The Android Activity UI can be designed through write a xml file.I thought that's a very smart way and very different from tradition Java GUI programming (i.e., swing and awt) because that's very similar with what a web page designer dose, especially the table layout of Android.
When you define some UI component (e.g. a button) in a res/layout/xxx.xml, you maybe need to get the UI component instance to do something, such as register a click listener. Hence, Android supply Activity.findViewById(id of control) to get the component instance from the xml.
Note. you need call Activity.setContentView(xxx.xml) before invoking Activity.findViewById(componet id). By the way, the parameter(e.g., component id) must be defined in xxx.xml that is the parameter of setContentView(). Or you will get a null return value of findViewById().
沒有留言:
張貼留言