I have a ListView with custom_row , every row has a textView1 and a textView2 , the list has now 2 records , and i have a button that is not on the list.
When i click the button i want to get the text from textView2 of the 2 records.
Is it possible?
I have a ListView with custom_row , every row has a textView1 and a
Share
I would take a shortcut, you
ListViewis being populated by anAdapterthat uses a dataset. This dataset can be almost any datastructure such as Array, ArrayList, etc.The layout you define, such as
custom_rowin you case only defines the structure of your view i.e. “where” items will show within on item on the list.On the other hand, it is still your responsibility to tell the
ListView“what” to show within thetextView1andtextView2. You do this using theAdapterwhich connects theListViewto the dataset. More often than not, theListViewis a one-to-one mapping of the dataset i.e. the first item on the list is the first item in you dataset (I don’t know what you are using for only two items, might be an array).The
ListViewcallsgetCount()on theAdapterto find out how many total views there will be. It then callgetView()for each view to be shown on the screen. It is in this method that you define what will actually show in a single view on the list (your custom_row).Now you would know which entry of the dataset is supposed to populate which view in the
ListViewso you can just read it off there. For example, if yourgetView()does:And the original dataset is an ArrayList named
listDataSetYou could just do
listDataSet.get(2).getSomeTextField()NOTE: You will have to manage the scope of the dataset so that it’s visible from wherever you are calling.