Kevin Kopf
Kevin Kopf

Reputation: 14210

onItemClickListener stops working after changing visibility of item child

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout /* not important */>

    <TextView /* not important */ />

    <TextView /* not important */ />

    <RelativeLayout
        /* not important */ 
        android:id="@+id/detailLayout"
        android:visibility="gone">

        <TextView /* not important */ />
    </RelativeLayout>

</RelativeLayout>

.

private class ItemClickListener implements AdapterView.OnItemClickListener
{
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id)
    {
        RelativeLayout detailLayout = (RelativeLayout) view.findViewById(R.id.detailLayout);
        int detailLayoutVisibility = detailLayout.getVisibility();

        if(detailLayoutVisibility == View.GONE)
        {
            detailLayout.setVisibility(View.VISIBLE);
        }
        else
        {
            detailLayout.setVisibility(View.GONE);
        }
    }
}

First when I click the item, the event fires and detailLayout changes visibility to View.VISIBLE, but then any further attempt to click it results in no event firing.

Upvotes: 1

Views: 130

Answers (2)

hehe
hehe

Reputation: 1304

First things first, create a global variable for your detailLayout instead of initializing it every time you click. Then in your onCreate set the click listener of detailLayout to this since you implemented the onClickListener.

Also, why did you implement AdapterView.OnItemClickListener instead of View.OnClickListener? You want to click a RelativeLayout not adapter right?

Instead of just setting the visibility of detailLayout to GONE, try also to do the same with the child views of detailLayout, i.e. set the visibility of the TextView inside the detailLayout to GONE.

Upvotes: 2

Matthew Shearer
Matthew Shearer

Reputation: 2795

try setting your detailLayout to

android:clickable="false"
android:focusable="false"

also, the stuff you say is unimportant, could very well be quite important.

Upvotes: 1

Related Questions