简体   繁体   English

Android(视图):ListView中的子位置取决于Android版本

[英]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. 我正在开发一个android-app,它处理一个带有多个TextViews的ListView作为子级。

The problem (already solved) came when I tried to get child from the parent view by using getChildAt(pos) method. 当我尝试使用getChildAt(pos)方法从父视图中获取子项时,问题就已经解决了。

I have tested my app in two devices with different android versions installed, and I got the following conclusions: 我已经在安装了不同Android版本的两台设备中测试了我的应用,并得出以下结论:

In android 2.2.1 the parent view refers their childs by using the following position-indexation: 在android 2.2.1中,父视图通过使用以下position-indexation引用其子级:

Parent. 父母

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

In android 4.0.3 the parent view refers their childs by using the following position-indexation: 在android 4.0.3中,父视图通过使用以下position-indexation引用其子级:

Parent. 父母

  • Child_A: position 0 Child_A:位置0
  • Child_B: position 1 Child_B:位置1
  • Child_C: position 2 Child_C:位置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. 因此,我想知道它从哪个版本更改了子索引协议,以便以一种或多种方式运行,具体取决于目标设备中安装的android版本。

What I want to do is somthing like this: 我想做的是这样的:

if androidVersion >= X then 如果androidVersion> = X然后

_ _ _Use new chlid-indexation protocol _ _ _使用新的chlid-indexation协议

else 其他

_ _ _Use old child-indexation protocol _ _ _使用旧的子索引协议

Thanks. 谢谢。

Check out this android.os.Build.VERSION . 看看这个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){

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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