简体   繁体   English

得到所有动态创建的linearlayout android java

[英]getting all dynamically created linearlayout android java

ScrollView sv = (ScrollView) v.findViewById(R.id.layout_question_content);
LinearLayout layout_questions = (LinearLayout) sv.findViewWithTag("layout_questions");
int childcount = layout_questions.getChildCount();
System.out.println("LinearLayout " + childcount);

I want to get All Linear Layout using tag but I get 我希望使用标签获得所有线性布局,但我得到了

java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.widget.ScrollView.findViewWithTag(java.lang.Object)' on a null object reference java.lang.NullPointerException:尝试在空对象引用上调用虚方法'android.view.View android.widget.ScrollView.findViewWithTag(java.lang.Object)'

All my LinearLayout including all its child are dynamically added 我的所有LinearLayout(包括其所有子项)都是动态添加的

XML

<ScrollView
        android:id="@+id/layout_question_content"
        android:clickable="true"
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_marginBottom="50px"
        android:layout_height="fill_parent">

</ScrollView>

The ScrollView is either not defined in your XML or your <ScrollView /> does not have the id layout_question_content . ScrollView未在XML中定义,或者<ScrollView />没有id layout_question_content Check that you have android:id="@+id/layout_question_content" set. 检查你是否设置了android:id="@+id/layout_question_content"

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

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