Reputation: 1005
Hi i have LinearLayout with horizontal orientation has two childrens as follows
<LinearLayout
android:id="@+id/clearAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/parent"
android:layout_marginBottom="0dp"
android:layout_marginRight="16dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_gravity="center_vertical"
android:background="@drawable/clear_all_bg"
android:padding="3dp"
android:src="@drawable/ic_close_white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:gravity="center"
android:paddingLeft="5dp"
android:text="Clear"
android:textColor="@android:color/holo_red_light"
android:textSize="@dimen/font_size_micro"
android:textStyle="normal" />
</LinearLayout>
At run time i have set OnClickListner for LinearLayout like this
clearAll = (LinearLayout) findViewById(R.id.clearAll);
clearAll.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i(TAG, "clearAll Click");
}
});
I tried with
android:duplicateParentState="true"
and
android:clickable="true"
but no use listener is not triggered
Upvotes: 0
Views: 3141
Reputation: 4182
it may be click to textview or imageview
Method 1: Try to take android:focusableInTouchMode="false" to textview and imageview
<LinearLayout
android:id="@+id/clearAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/parent"
android:layout_marginBottom="0dp"
android:layout_marginRight="16dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_gravity="center_vertical"
android:background="@drawable/clear_all_bg"
android:padding="3dp"
android:focusableInTouchMode="false"
android:src="@drawable/ic_close_white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:gravity="center"
android:paddingLeft="5dp"
android:text="Clear"
android:focusableInTouchMode="false"
android:textColor="@android:color/holo_red_light"
android:textSize="@dimen/font_size_micro"
android:textStyle="normal" />
</LinearLayout>
Method 2: Or set id to image view and Textview and try this...
textview.setEnabled(false);
Upvotes: 1