在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对象。
首先给Main布局一些id。喜欢:
<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);