I have two layout files, one for main activity and the other XML file is for my custom list view. I want to access the ID of the views in my layout file but the main activity in the R square is only the IDs from the XML file. I would like to know how I can add an ID to R classes or access them through another medium.
Thank you and sorry if it's a lame question but I am fairly new to Android.
This is the main activity
& lt; LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" Android: layout_width = "Fill_parent" Android: layout_height = "fill_parent" Android: orientation = "vertical" & gt; & Lt; ListView Android: id = "@ + id / list1" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" & gt; & Lt; / ListView & gt; & Lt; / LinearLayout & gt; This is the layout file
& lt; LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" Android: layout_width = "match_perrent" android: layout_heck = "match_perrent" android: orientation = "horizontal" & gt; & Lt; ImageView Android: id = "@ + id / imgSports" Android: layout_width = "wrap_content" android: layout_height = "fill_parent" android: gravity = "center_vertical" /> & Lt; TextView android: id = "@ + id / rowTitle" Android: layout_width = "fill_parent" android: layout_height = "fill_parent" android: gravity = "center_vertical" /> & Lt; / LinearLayout & gt;
When you create an activity, it will create its default layout xml as far as I Understand the problem, you want the same activity to display a list. If this is the case, then I suggest that you try to keep your design in the default activity layout, which will create an ID in R. Apart from this, I say the basic Android tutorial available on the Android Developers site will help "Create your first app". You understand this.
No comments:
Post a Comment