gpt4 book ai didi

即使将其可见性设置为 GONE,Android View 仍会获得 OnClick()

转载 作者:行者123 更新时间:2023-12-04 23:51:29 25 4
gpt4 key购买 nike

我知道关于这个问题的问题很少,但他们都在使用动画。我的 Activity 中根本没有动画。我有一个 TextView,默认情况下它是可见的,并且根据我在启动画面中获得的功能标志设置为 Gone。

这是我的 xml 文件:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/profile_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/profile_bg"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingTop="?android:actionBarSize">

<TextView
android:id="@+id/payments_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:background="@drawable/profile_payment_bg"
android:clickable="true"
android:drawableLeft="@drawable/ic_profile_payment"
android:drawablePadding="8dp"
android:gravity="center_vertical"
android:onClick="onClick"
android:padding="8dp"
android:text="Payment"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="@android:color/white" />

...

</LinearLayout>

</FrameLayout>

尽管我将 Clickable 和 OnClickListener 功能分别设置为 false 和 null,但即使我的付款按钮不可见,也会调用 OnClick() 功能:(
@Override
protected void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_profile);

this.mPayments = (TextView) findViewById(R.id.payments_btn);

// Check if payment functionality available for the Passenger
final PassengerFeatureResponse cachedFeature = FeatureResponse.fromJsonString(PreferenceUtils.getFeatureResponse(this));
if (cachedFeature == null || !cachedFeature.isMade())
{
this.mPayments.setVisibility(View.GONE);
this.mPayments.setClickable(false);
this.mPayments.setOnClickListener(null);
}
}

我什至尝试将可见性设置为从 xml 文件中消失,并将其设置为从代码中可见,但是功能是相同的 :(

可能是因为我定义了 onClick xml 文件中的功能,如果我从代码中设置单击监听器,我的问题将得到解决,但是,我正在寻找以这种方式解决问题。

任何建议将不胜感激。谢谢。

最佳答案

试试这个 FrameLayout像这样

  this.frameMain= (FrameLayout) findViewById(R.id.profile_layout);
if (cachedFeature == null || !cachedFeature.isMade())
{
this.mPayments.setVisibility(View.GONE);
this.mPayments.setClickable(false);
this.mPayments.setOnClickListener(null);
this.frameMain.invalidate();
}

关于即使将其可见性设置为 GONE,Android View 仍会获得 OnClick(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30841645/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com