1

我正在尝试通过代码将 TextView 设置为不可见,但它不起作用。我的 XML 声明是(在 LinearLayout 内):

    <TextView android:text="\nVideo" android:visibility="visible" 
android:layout_width="wrap_content" android:layout_height="wrap_content" 
android:id="@+id/exhibitor_profile_videoSectionLabel" 
android:textAppearance="?android:attr/textAppearanceMedium"></TextView>

我的Java是:

setContentView(R.layout.exhibitor_profile);
    TextView vidLabel=new TextView(this);
            vidLabel.findViewById(R.id.exhibitor_profile_videoSectionLabel);
    vidLabel.setVisibility(View.INVISIBLE);

“不可见”调用仅在某些情况下进行,但即使我将调用移到条件之外以保证调用,TextView 仍然可见。在这一切过程中,LogCat 一直保持沉默,否则我很乐意发布它的内容。

4

1 回答 1

3

您不应该创建一个新的TextView. 您正在尝试查找现有的:

setContentView(R.layout.exhibitor_profile);
TextView vidLabel = findViewById(R.id.exhibitor_profile_videoSectionLabel);
vidLabel.setVisibility(View.INVISIBLE);
于 2012-06-05T20:05:14.530 回答