2014-01-18 25 views
1

在Xamarin中,如何獲取當前版面,以便從版面中刪除子版?從版面中刪除子版

這裏是我的代碼:

SetContentView (Resource.Layout.AutoLinkTextView); 

TextView Email = (TextView)FindViewById(Resource.Id.TextViewEmail); 
Email.Text = "Test Email of [email protected]"; 

TextView Phone = (TextView)FindViewById(Resource.Id.TextViewPhone); 
Phone.Text = "Test Phone of 0800 64 64 64"; 

TextView Web = (TextView)FindViewById(Resource.Id.TextViewWeb); 
Web.Text = "Test Address of http://www.google.com" + "\n" + "Test Address of http://www.stackoverflow.com"; 

在我AutoLinkTextView佈局我有以下ID的TextView的,我希望從佈局中刪除:

android:id="@+id/TextViewMap" 

我可以請有一定的幫助去做這個?

在此先感謝

編輯

我能有一些幫助的代碼?

這裏是我的代碼:

LinearLayout layout = (LinearLayout)FindViewById (0); 
View ViewToRemove = layout.GetChildAt (1); 
layout.RemoveView (ViewToRemove); 

與上面的代碼,沒有TextView的對象都顯示在所有。

+0

你可以使用removeView()函數。 –

回答

2

首先給一些主佈局標識。像:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/linearLayout"> 
//All ur textviews 
</LinearLayout> 

然後,在的onCreate()編寫代碼:

LinearLayout _linear = (LinearLayout) findViewById(Resource.id.linearLayout); 
TextView textViewMap = (TextView) findViewById(Resource.id.TextViewMap); 
_linear.removeView(textViewMap);