Wednesday, 10 December 2014

How can I setText to a TextView in every single row of my ListView



Hi guys I am new to Android and also to stackoverflow, Greetings and thanks for the help.


I have 2 Xml files for the same activity. One that contains a ListView and the second as my custom layout for an ArrayAdapter that populates a ListView which is also included on my first layout:



<include android:id="@+id/lv" layout="@layout/lv_row" />


ListView Custom Layout (lv_row.xml):



<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="fill_parent" android:layout_height="fill_parent">


<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/icon"
android:src="@drawable/ic_launcher"/>
<TextView
android:layout_toRightOf="@+id/icon"
android:layout_width="fill_parent"
android:layout_height="38dp"
android:textSize="30sp"
android:id="@+id/label"/>
<TextView
android:layout_toRightOf="@+id/icon"
android:layout_below="@+id/label"
android:layout_width="fill_parent"
android:layout_height="12dp"
android:gravity="bottom"
android:id="@+id/label2"

android:textSize="12sp"/>

</RelativeLayout>


This is my adapter:



final ArrayAdapter<String> Array = new ArrayAdapter<String>(this,R.layout.lv_row,R.id.label,myList);


I save strings one by one into "myList" and display them on my ListView, what I want to do is to enumerate the elements on my list view by using idNum.setText(iterating_variable.toString())... but it won't work because idNum always get the value that was set on the XML file.


This is the code I use to link the second XML with my Java code



lv = (RelativeLayout) findViewById(R.id.lv);
idNum = (TextView) lv.findViewById(R.id.label2);


Thanks again for your help.


No comments:

Post a Comment