简体   繁体   中英

Android (View): Child position inside ListView depending on android version

Im developing an android-app which handles a ListView with several TextViews within it as childs.

The problem (already solved) came when I tried to get child from the parent view by using getChildAt(pos) method.

I have tested my app in two devices with different android versions installed, and I got the following conclusions:

In android 2.2.1 the parent view refers their childs by using the following position-indexation:

Parent.

  • Child_A: position 2
  • Child_B: position 1
  • Child_C: position 0

In android 4.0.3 the parent view refers their childs by using the following position-indexation:

Parent.

  • Child_A: position 0
  • Child_B: position 1
  • Child_C: position 2

So, I would like to know from which version it changed the child indexation protocol in order to operate in one way or antoher depending on the android version installed in the target device.

What I want to do is somthing like this:

if androidVersion >= X then

_ _ _Use new chlid-indexation protocol

else

_ _ _Use old child-indexation protocol

Thanks.

Check out this android.os.Build.VERSION .

    if(Build.VERSION.SDK_INT >= 4.0){
        //this code will be executed on devices running on DONUT (NOT ICS) or later
    } else if(Build.VERSION.SDK_INT < 4.0){

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM