2011-06-09 54 views
0

相關XML:設置LinearLayout的可見性時出現問題

<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異常。誰知道爲什麼?

+0

你叫'linearLayoutVideoFeedListView.setVisibility(消失)''後,LV =(ListView控件)findViewById(R.id.list_video_feed)'? – 2011-06-09 14:43:01

+0

如果其最頂層的父項是否可以隱藏根視圖? – Spidy 2011-06-09 14:53:49

+0

@Gabriel是的,我是 – yellavon 2011-06-09 14:58:07

回答

1

如果你打電話

linearLayoutVideoFeedListView.setVisibility(消失)之前linear_layout_video_feed_list_view尚未奠定了

它會導致空指針。 如果這確實是這裏的問題,儘量誇大它:

LayoutInflater吹氣=(LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); RelativeLayout myView =(RelativeLayout)mInflater.inflate(R.id.linear_layout_video_feed_list_view,null);

希望幫助

+0

當聲明mContext和mInflater時:Context mContext; mInflater是什麼類型? – yellavon 2011-06-09 15:05:49

+0

另一個想法是,'linearLayoutVideoFeedListView'必須佈置,因爲我可以調用嵌套在'linearLayoutVideoFeedListView'中的'lv.setVisibility(GONE)'。對? – yellavon 2011-06-09 15:19:10

-2

我會嘗試

linearLayoutVideoFeedListView.setVisibility(LinearLayout.GONE); 

那是什麼一直爲我工作

+0

我試過了,我仍然得到NullPointerException。任何其他想法?謝謝。 – yellavon 2011-06-09 16:36:34