【发布时间】:2016-10-20 20:39:54
【问题描述】:
我在布局中有这个寻呼机,我尝试根据条件为寻呼机和线性布局设置可见性,但它不起作用我在互联网上搜索并且都有相同的答案,知道吗?
这是xml
<LinearLayout
android:orientation="vertical"
android:id="@+id/error_linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:visibility="visible">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="@mipmap/ic_launcher"
android:id="@+id/error_image_view"
android:layout_weight="0.59" />
<TextView
android:text="This Screen Is Not Active"
android:textSize="30sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/error_text_view"
android:layout_weight="0.59" />
</LinearLayout>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"></android.support.v4.view.ViewPager>
这是主要活动
ViewPager imagePager;
LinearLayout errorLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_pager);
//views
errorLayout = (LinearLayout) findViewById(R.id.error_linear_layout);
imagePager = (ViewPager) findViewById(R.id.pager);
IsActive();
}
public void IsActive()
{
String x = "x";
if (x=="x")
{
imagePager.setVisibility(View.VISIBLE);
errorLayout.setVisibility(View.INVISIBLE);
}else
{
imagePager.setVisibility(View.INVISIBLE);
errorLayout.setVisibility(View.VISIBLE);
}
}
【问题讨论】:
-
用
x.equals("x");替换x == "x" -
不工作可见性错误因为我在 onCreate 中尝试没有任何方法并且不工作
-
在java中你永远不应该将字符串(当你对它们的内容感兴趣时)与'=='进行比较
-
好的,我将其编辑为 x.equals("x");并且不工作错误在于可见性
-
哪个错误,能贴一下日志吗?