On Monday, October 14, 2013 8:49:14 PM UTC+8, TreKing wrote:
>
>
> On Mon, Oct 14, 2013 at 12:42 AM, galapogos <[email protected]<javascript:>
> > wrote:
>
>> I have a list that is multiple pages long, and I'm trying to get the list 
>> index of the item that is selected using radio buttons. In 
>> onClickRadioButton() which I'm passing in my current View, I'm setting the 
>> myview as view.getParent() and the list index as ((ViewGroup) 
>> myview.getParent()).indexOfChild(myview).
>>
>> The listindex is correct (starts from 0) when the list is 1 page long, 
>> but whenever I scroll down a list that's longer than a page, the list 
>> index gets reset to 0 based on the item that's on the top of the page. Does 
>> anyone know what I'm doing wrong? Does is have anything to do with my View 
>> and getParent()?
>>
>
> It's hard to follow your description. Try posting a small bit of relevant 
> code.
>
>
> -------------------------------------------------------------------------------------------------
> TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago 
> transit tracking app for Android-powered devices
>

Sorry for the confusion. Here's some relevant code.

My onClickRadioButton():

  public void onClickRadioButton(View v) {
    View vMain = ((View)v.getParent());
    if (radioBut != null) {
      radioBut.setChecked(false);
    }
    radioBut = (RadioButton)v;
    if (radioBut.isChecked()) {
      listIndex = ((ViewGroup) vMain.getParent()).indexOfChild(vMain);
    } else {
      radioBut = null;
      listIndex = -1;
    }
  }

It seems that View/ViewGroups relate only to what's visible on the screen? 
So, when I use indexOfChild, the index starts from the first visible item 
on the screen, rather than the first item of the actual View/Layout. How do 
I get the actual index of the list items starting from the very first one, 
rather than the first visible one?

Thanks!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to