I have posted the same question on google's android-developer's forum. I am repeating here:
I have a TableLayout with one TableRow. The first column/cell is a ListView. The second cell/column is a TableLayout again which consists of 2 ListViews.
When i inflate the xml layout, everything looks fine and i have set of adapters for each of the 3 ListViews.
I have added dummy elements into these lists via adapters and am able to scroll up and down the list.
But the onItemClick is not getting triggered.
The following is my layout file -
<RelativeLayout android:id="@+id/top_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:text="Edit"
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
<TextView
android:text="dummy1"
android:textStyle="bold"
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/button1"
android:layout_centerVertical="true"
android:paddingLeft="25dip"
android:textSize="18dip">
</TextView>
<Button
android:id="@+id/button2"
android:layout_alignParentTop="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Cancel"
android:layout_alignParentRight="true">
</Button>
<TextView
android:layout_alignParentTop="true"
android:text="dummy2"
android:textStyle="bold"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/textView4"
android:layout_toLeftOf="@+id/button2"
android:layout_centerVertical="true"
android:paddingRight="25dip"
android:textSize="18dip">
</TextView>
</RelativeLayout>
<TableLayout android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:shrinkColumns="1">
<TableRow android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:divider="@android:color/black"
android:dividerPadding="2dip">
<ListView
android:id="@+id/listView1"
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
>
</ListView>
<TableLayout android:id="@+id/tableLayout2"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:shrinkColumns="1">
<TextView
android:text="dummy3"
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:padding="8dip"
android:textSize="18dip"
android:background="#ff238E23">
</TextView>
<ListView
android:id="@+id/listView2"
android:layout_height="0dip"
android:layout_weight="1"
android:drawSelectorOnTop="false"
android:divider="@android:color/white"
android:dividerHeight="2dip"
android:layout_width="match_parent"
android:clickable="true"
android:focusable="true"
>
</ListView>
<TextView
android:text="dummy4"
android:textSize="18dip"
android:textStyle="bold"
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff0000ff"
android:padding="8dip">
</TextView>
<ListView
android:id="@+id/listView3"
android:layout_height="0dip"
android:layout_weight="1"
android:drawSelectorOnTop="false"
android:divider="@android:color/white"
android:dividerHeight="2dip"
android:layout_width="match_parent"
android:clickable="true"
android:focusable="true"
>
</ListView>
</TableLayout>
</TableRow>
</TableLayout>
And in the java file, i do
ListView lv = (ListView) findViewById(R.id.listView1);
lv.setAdapter(new EfficientAdapterLeft(this));
lv.setOnItemClickListener(new OnItemClickListener()
{ @Override public void onItemClick(AdapterView arg0, View view, int arg2, long arg3) { Log.v("blah","arg2 " + arg2); Log.v("blah","arg3 " + arg3); } });
I do similar things for the remaining two lists R.id.listView2 and R.id.listView4. They instantiate different adapters but nothing drastically different.
I don't see the logs getting printed. Why am i unable to click on the items and get the onClickItem listener get triggered? Even doing this lv.setFocusable(true); lv.setClickable(true); does not help.
Any idea what's happening?
Thanks.