设置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>

相关代码:

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)导致nullpointer异常。有人知道为什么吗?

如果在调用之前linear_layout_video_feed_list_view尚未布局

linearLayoutVideoFeedListView.setVisibility(GONE)

它将导致一个空指针。如果这确实是这里的问题,试着给它充气:

LAYOUT充气器充气器=(LAYOUT充气器)mContext.getSystemService(Context.LAYOUT_inflater_SERVICE);RelativeLayout myView=(RelativeLLayout)mInfrater.inflate(R.id.linear_layout_video_feed_list_view,null);

希望对有所帮助

我会尝试

linearLayoutVideoFeedListView.setVisibility(LinearLayout.GONE); 

这一直对我有效

最新更新