tablelayout programmatically set selection to a row
tablelayout programmatically set selection to a row
I have a table built using a tablelayout. The user selects a row then I save the ID. At times they will leave this page and when they return to the page I would like the same row selected. Here is what I have tried as I reload the table.
if(pProgram.getId() == selectedProgramId)
tr.setSelected(true);
tr.setActivated(true);
I know I am hitting this if statement at the correct times but I can not seem to get the row to be selected. No row is selected each time I come back to the page.
Any suggestion as to what I might be doing wrong?
Thank you for all your help!
Good Question. I use a OnFocusChangeListener where I set the setBackgroundResource of the view. This seems to work here but not when I build the table.
– Andy
Aug 20 at 15:59
1 Answer
1
Alright so from what i gather you either need to set the background resource programmatically at that point in your code or trigger the OnFocusChangeListener.
The first option should be easy enough, for the second it seems like you can call View.requestFocus(). For more info on requesting focus check out this questions How to set focus on a view when a layout is created and displayed?
Thank you! That makes since. I tried this and see that it is using the correct view but it seems like something is taking if and forcing it to the first row. Is there an easy way to figure out what is doing that?
– Andy
Aug 20 at 17:57
That is probably the default behaviour for when the view becomes visible... to be honest i am not sure if you should really be using the focused property of the view to decide which line to highlight. I would rather suggest using an onClickListener and highlighting based on which cell is clicked
– StarterPack
Aug 20 at 21:16
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
how did you implement selecting of rows? Did you use any framework for that?
– StarterPack
Aug 20 at 15:37