Reputation: 1811
Have following piece of layout:
<LinearLayout android:id="@+id/colleagues_show_email_linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:clickable="true"
android:background="?attr/clickableItemBackground">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"/>
<TextView android:id="@+id/colleagues_show_email_textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"/>
</LinearLayout>
When i click on ImageView, LinearLayout changes background the same way as in the ListView. But clicking on TextView doesn't change background. What's wrong?
Update I had a View.OnClickListener (with only onClick(View v) {Log.d(TAG, "Email onClick"); }) on the TextView and that was the issue. After removing setOnClickListener line it starts to work as expected.
Upvotes: 0
Views: 1043
Reputation: 1
To change the colour of the layout
imageview.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
linearlayout.setBackgroundColor(
Color.parseColor("your colourcode(ex.#AE00FF)"));
}
});
To get the colour
ColorDrawable cd = (ColorDrawable) listview.getBackground();
int colorCode = cd.getColor();
Upvotes: 0
Reputation: 2173
The ImageView
has no click event but the TextView
handles the click event on its own. When you tap it, it allows you to edit the text inside. You are actually not clicking on the List item, so it doesn't execute the List selector. You will have to manage to fire the List item onClick
event from the TextView
, probably from the TextView
's onClick
event... or maybe THIS THREAD could help also. It suggests using android:descendantFocusability="blocksDescendants"
on your layout.
Good luck
Upvotes: 0