0

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.

tiktak
  • 1,801
  • 2
  • 26
  • 46

3 Answers3

1

Set the textview height and width to wrap_content.

Amit Thaper
  • 2,117
  • 4
  • 26
  • 49
  • I think the textview is not visible so textview click not working. You need to set property android:text="Sample Text" android:layout_width="match_parent" android:layout_height="wrap_content" android:textsize="25sp" – Amit Thaper Dec 17 '14 at 11:53
  • No, it was visible with text (i set it via java code). – tiktak Dec 17 '14 at 12:22
  • Can you please send the code so that i can properly verify and resolve errors – Amit Thaper Dec 17 '14 at 12:26
  • Thanks for your patience. See updated question now. I still don't know how to fix this issue with onClickListener but it works without it. – tiktak Dec 17 '14 at 13:32
  • _textView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Log.d(TAG, "Email onClick"); } }); – Amit Thaper Dec 17 '14 at 13:48
0

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();
Ben Pearson
  • 7,532
  • 4
  • 30
  • 50
0

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

Community
  • 1
  • 1
mihail
  • 2,173
  • 19
  • 31
  • I don't have list item here. Just style from it. – tiktak Dec 17 '14 at 12:24
  • it's basically the same, you have a layout with selector background. You need to handle the `TextView`s `onClick` to simulate click on the linear layout – mihail Dec 17 '14 at 13:30