ZaptechDev Kumar
ZaptechDev Kumar

Reputation: 164

LinearLayout not getting clicked

I tried a lot but, my Linearlayout as below not getting clicked :

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/ll_top_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:focusableInTouchMode="false"
        android:orientation="vertical">

  <LinearLayout
   android:focusableInTouchMode="true"
   android:clickable="true"
   android:id="@+id/ll_Promos"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:layout_below="@id/vv_divider4"
   android:layout_marginTop="@dimen/dimen_5"
   android:orientation="horizontal"
   android:padding="@dimen/dimen_10">

                <ImageView
                    android:id="@+id/iv_restaurant_promo"
                    android:layout_width="@dimen/dimen_25"
                    android:layout_height="@dimen/dimen_25"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="@dimen/dimen_5"
                    android:layout_marginRight="@dimen/dimen_5"
                    android:src="@drawable/promos" />

                <com.app.thelist.view.CustomTextView
                    android:id="@+id/txt_restaurant_promo"
                    style="@style/RegularFont"
                    android:layout_gravity="center"
                    android:layout_marginRight="@dimen/dimen_5"
                    android:layout_weight="1"
                    android:padding="@dimen/dimen_5"
                    android:text="@string/promo"
                    android:textColor="@color/txt_sub_title"
                    android:textSize="@dimen/sp_15" />

                <ImageView
                    android:id="@+id/iv_restaurant_promo_next"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="@dimen/dimen_5"
                    android:src="@mipmap/app_icon"
                    android:visibility="gone" />

            </LinearLayout>
 </LinearLayout>
</ScrollView>

The above is my xml file, and I have make my LinearLayout named : ll_Promos not getting clicked. I have implemented my onClick() as below in java file :

ll_promos = (LinearLayout) findViewById(R.id.ll_Promos);
        ll_promos.setOnClickListener(this);
 case R.id.ll_Promos:
            Intent intentProm = new Intent(Activity1.this, Activity2.class);
            startActivity(intentProm);
            break;

Upvotes: 1

Views: 81

Answers (1)

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75798

Remove

  android:focusableInTouchMode="false" // Problem starts from here

Set whether this view can receive focus while in touch mode. Setting this to true will also ensure that this view is focusable.

And Add

android:focusableInTouchMode="true"
android:clickable="true"

Upvotes: 2

Related Questions