gpt4 book ai didi

java - 为什么我的 ListView 在 TableRow 中包含 RatingBar 时不可点击?

转载 作者:行者123 更新时间:2023-11-30 11:42:27 24 4
gpt4 key购买 nike

当我的 ListView 的 TableRow 中有一个 RatingBar 时,我的 onListItemClick 在我触摸一行时没有被触发。当我执行 bar.setVisibility(View.GONE) 或只是删除控件时,这些行再次可点击。

如何才能在添加 RatingBar 时,onListItemClick 仍会针对该行触发?我试过设置 focusable="false" 但它仍然不起作用。

想法????

这是我在 TableRow 中的 RatingBar 的 XML:

<TableRow
android:id="@+id/tableRow2x"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<RatingBar
android:id="@+id/rtbProductRating"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:numStars="5"
android:rating="3.5"
android:layout_marginLeft="8dip"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
android:isIndicator="false"
android:focusable="false"
android:focusableInTouchMode="false"
style="@style/starRatingBar"
/>

</LinearLayout>

</TableRow>

这是我的代码:

public class MainFragment extends ListFragment {

public void onListItemClick(ListView parent, View v, int position, long id)
{
//... does stuff
}

最佳答案

onClick 事件已被 RatingBar 拦截,因此不会触发 onListItemClick。

可以继承RatingBar类,重写onTouchEvent方法,返回false。

@Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(MotionEvent event)
return false;
}

关于java - 为什么我的 ListView 在 TableRow 中包含 RatingBar 时不可点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11697075/

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