2

I want,a new View appears in my ListView Item, if I click this Item like this, where (1) and (2) are clicks

enter image description here

and I can do it, but when I want to click again this Item, i.e. to hide that new View, then Itemclick reacts no longer in the way it should do.

I perform the add View Operation in my onItemClickListener right to the properly position

My code is the following

...
list_view.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Log.i("TAG", "onItemClick:: BEGIN");

            switch (position) {
                case 0 : 
                    Log.i("TAG", "onItemClick:: before addTitle");                      
                    showFieldList(view);
                    Log.i("TAG", "onItemClick:: after  addTitle");
                break;              
                ...                 
            }

            Log.i("TAG", "onItemClick:: END");
        }
});
...

I tried to show the behaviour in my Log and after the first Click I can see my Log Entry "TAG" with the values

onItemClick:: BEGIN

onItemClick:: before addTitle

onItemClick:: after addTitle

onItemClick:: BEGIN

but the next clicks show nothing and as said, that Item doesn't react anymore but I can see instead my client_adapter LOG and just the entries of getGroupView Method are shown when I click on Item.

I just wanted to remark too, that it also behaves like this, if I attach the OnGroupExpand/OnGroupCollapse/OnGroupClick Listeners of ExpandableListView.

Sum up: I have a ListView and if I click the first Item, this one expand to show an ExpandableListView and if I'click again, this should be collapsed but this doesn't behave like this, so that the ExpandableListView assumes the control over entire Item.

Can anyone tell me, why the item loses control of clicks and this is won by the ExpandableListView FieldList? Thank you in advance!

Rest of code

    private View showFieldList(View view) {

        // Retrieving Item Layout. (= view Layout)
        RelativeLayout item_layout = (RelativeLayout) view.findViewById(R.id.relLayoutDrawer);

        // Retrieving "title" Element
        TextView title_tv = (TextView)view.findViewById(R.id.title);

        View row = View.inflate(context, R.layout.field_list, null);

        // Getting Field names
        Resources res = getResources();
        String fields = res.getString(R.string.fields);         

        client = (ExpandableListView)row.findViewById(R.id.field_expandable_list);

        client.setFocusable(false); //<< ADDED TO WORK  

        client_adapter = new ClientAdapter(context, fields);



        // When I comment this Line, `onItemClick` works
        // if not, then client_adapter assummes control

        client.setAdapter(client_adapter); 

        // Setting "Subtitle" under "title" aligning both left borders
        params.addRule(RelativeLayout.ALIGN_LEFT, title_tv.getId());
        params.addRule(RelativeLayout.BELOW, title_tv.getId());     
        item_ayout.addView(row, params);    
    }

Here my drawer_list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relLayoutDrawer"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:background="@android:color/black">

    <ImageView
        android:id="@+id/icon"
        android:layout_width="25dp"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/title"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="12dp"
        android:layout_marginRight="12dp"
        android:contentDescription="@string/desc_list_item_icon" />

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_toRightOf="@id/icon"
        android:minHeight="?android:attr/listPreferredItemHeightSmall"
        android:textAppearance="?android:attr/textAppearanceListItemSmall"
        android:textColor="@color/metallic_silver"
        android:gravity="center_vertical"
        android:paddingRight="40dp"/>

    <TextView android:id="@+id/counter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@layout/counter_bg"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="8dp"/>

</RelativeLayout>
Gödel77
  • 839
  • 3
  • 15
  • 27

2 Answers2

2

The problem exists because you have ExpandableListView nested in your ListView. When ExpandableListView is hidden, only ListView receives onClick events, but when it appears it consumes all the onClick events, therefore your ListView doesn't react on clicking anymore.

You can either follow this topic: ListView OnItemClickListener Not Responding?

Or just go for approach offered by momo in one of comments - using only ExpandableListView with just more levels of depth.

Community
  • 1
  • 1
Piotr Chojnacki
  • 6,837
  • 5
  • 34
  • 65
  • Piotr but I didn't attach any Listener to the ExpandableListView. I have developed ListViews with customized Items (Linear and Relative Layouts with ImageViews, Buttons, etc) and I always had to attach their Listeners, in order that they react. Thx – Gödel77 Oct 09 '14 at 11:37
  • @Gödel77 I think it consumes the events anyway. They're just not delegated to any specific `Listener`. – Piotr Chojnacki Oct 09 '14 at 11:47
1

Solved!

I properly wrote again onCollapsedGroupListener, onExpandedGroupListener and onClickedGroupListener and I added the next line to the last code

client = (ExpandableListView)row.findViewById(R.id.field_expandable_list);
...
client.setFocusable(false);
Gödel77
  • 839
  • 3
  • 15
  • 27
  • Now my trouble is to populate the nested `ExpandablewListView`, I have opened a new thread with a Bounty (50). Group is properly populated but not the children. Each time, it should call `getChildView` of this nested ExpandableListView`, It calls `getView` of Main `ListView`http://stackoverflow.com/questions/26379164/getchildview-gets-not-called – Gödel77 Oct 17 '14 at 10:14