设置的LinearLayout的可见性问题 [英] Issue when setting visibility of LinearLayout
问题描述
相关XML:
<LinearLayout
android:id="@+id/linear_layout_video_feed_list_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="2">
<ListView
android:id="@+id/list_video_feed"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
</LinearLayout>
相关code:
linearLayoutVideoFeedListView = (LinearLayout) findViewById(R.id.linear_layout_video_feed_list_view);
lv = (ListView) findViewById(R.id.list_video_feed)
lv.setVisibility(GONE)
的作品,但 linearLayoutVideoFeedListView.setVisibility(GONE)
将导致空指针异常。任何人都知道为什么吗?
lv.setVisibility(GONE)
works but linearLayoutVideoFeedListView.setVisibility(GONE)
causes nullpointer exception. Anyone know why?
推荐答案
如果linear_layout_video_feed_list_view尚未奠定了你打电话之前
If linear_layout_video_feed_list_view has not been laid out before you call
linearLayoutVideoFeedListView.setVisibility(消失)
linearLayoutVideoFeedListView.setVisibility(GONE)
这将导致空指针。
如果这里确实是问题,尝试充气吧:
it will result in a Null Pointer. If this is indeed the problem here, try inflating it:
LayoutInflater吹气=(LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout的MyView的=(RelativeLayout的)mInflater.inflate(R.id.linear_layout_video_feed_list_view,NULL);
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); RelativeLayout myView = (RelativeLayout) mInflater.inflate(R.id.linear_layout_video_feed_list_view, null);
希望帮助
这篇关于设置的LinearLayout的可见性问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!