android - How to reference TextView in RelativeLayout -
still total noob here...
i'm trying render specs football match (teams, time, tournament etc.)
i have created team.xml:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" > <imageview android:id="@+id/teamimageview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginright="2dp" android:adjustviewbounds="true" android:src="@drawable/sofabold_launcher" android:layout_alignwithparentifmissing="false" android:clickable="false" android:croptopadding="true" android:contentdescription="@string/teamlogocontentdescription"/> <textview android:id="@id/teamname" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/teamname" android:textsize="14sp" android:textstyle="bold" android:layout_centervertical="true" android:layout_torightof="@+id/teamimageview"/> </relativelayout>
a teams.xml:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="bottom" android:orientation="vertical" > <include android:layout_width="wrap_content" android:layout_height="wrap_content" layout="@layout/team" android:layout_alignparenttop="true" android:layout_alignparentleft="true" android:id="@+id/hometeam"/> <include android:layout_width="wrap_content" android:layout_height="wrap_content" layout="@layout/team" android:layout_below="@id/hometeam" android:id="@+id/awayteam"/> </relativelayout>
and have matchlayout.xml including teams.xml
my initial attempt create 1 big layout different element , reference them id in matchholder , populating them using
matchholder.hometeamname.settext(match.gethometeamname());
now i've tried changing populatematchholder to:
private void populatematchholder(view convertview, basematchholder matchholder) { matchholder.teams = (relativelayout) convertview.findviewbyid(r.id.teams); }
and cant figure out how reference textview (home team name) inside relativelayout (teams) inside relativelayout (match).
am totally missing point here? need have id called hometeamname somewhere? , awayteamname? isn't enough have teamname twice? once in hometeam include of team.xml , once in awayteam include of team.xml.
hope it's clear mean :-) it's pretty late , i'm tired :-/
thanks in advance
if want reference view id id should unique in given scope, otherwise android return first view given id.
so if teamsview.findviewbyid(r.id.teamname)
teamname view hometeam layout because there 2 view same id on teams.xml(on included hometeam , 1 included awayteam).
solution: first team layout each team , set team name example:
view hometeam = teamsview.findviewbyid(r.id.hometeam); textview hometeamname = hometeam.findviewbyid(r.id.teamname); hometeamname.settext("blablabal"); //the same other team
btw. use android:id="@+id/teamname"
instead of android:id="@id/teamname"
Comments
Post a Comment