首页 > 解决方案 > 如何从android中的线性布局中获取视图?

问题描述

我想从 Linearlayout 获得不同的视图,但它总是让我成为其中之一。这是我的代码:

int count = LinearLayoutItemHolder.getChildCount() ;
for(int i = 0 ; i <count ; i++){
   Customview cs = LinearItemHolder.getChildAt(i) ;
   Log.d(TAG,"value of cs " + cs) ;
   Log.d(TAG,"value : " +    cs.txtText.getText() ) ;
}

我的 LinearLayoutHolder 有 3 个孩子,但它总是返回我最后一个。

cs id 的值:

run: com.example.mine.happyp.View.CustomView{2a6e0e3 V.E...... ......I. 0,0-0,0}
                          run: com.example.mine.happyp.View.CustomView{c251ae0 V.E...... ......I. 0,0-0,0}
                          run: com.example.mine.happyp.View.CustomView{33ce199 V.E...... ......I. 0,0-0,0}
                          run: 3
                          run: com.example.mine.happyp.View.CustomView{2fedc5e V.E...... ........ 0,0-720,660}
                          run: com.example.mine.happyp.View.CustomView{c5ca83f V.E...... ........ 0,660-720,1320}
                          run: com.example.mine.happyp.View.CustomView{e71050c V.E...... ........ 0,1320-720,1980}

标签: javaandroidandroid-linearlayout

解决方案


推荐阅读