I need your help!
I have a main activity that contains 2 fragments (one for the header and one for the multicolumn list), one of the fragments is a ListFragments contains a multicolumn ListView, which is boxed in a scrollable view. This ListFragment overrides the onItemClickListener method. I can scroll the view and everything, but when I click on the listview, the listener is not invoked!
I have tried many different solutions, like trying to block focusability for views, but nothing has worked so far. Maybe you guys can help me out.
The parent activity containing the two fragments:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1"
android:descendantFocusability="blocksDescendants"
tools:context=".MainWindow"
>
<fragment
android:id="@+id/headerfragment"
android:name="lindcom.mobile.estock.fragments.ListHeaderFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
/>
<fragment
android:id="@+id/unitlistfragment"
android:name="lindcom.mobile.estock.fragments.UnitsListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
/>
</LinearLayout>
This is the layout I use for my multicolumn list:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="false"
android:focusableInTouchMode="false"
android:descendantFocusability="blocksDescendants" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1" >
<TextView
android:id="@+id/unitsCol1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.40"
android:ellipsize="marquee"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"
/>
<TextView
android:id="@+id/unitsCol2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.40"
android:ellipsize="marquee"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"
/>
<TextView
android:id="@+id/unitsCol3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:ellipsize="marquee"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"
/>
</LinearLayout>
</ScrollView>
The above layout is populated in an async task, after I have fetched the data:
ListAdapter adapter = new SimpleAdapter(
fragment.getActivity().getBaseContext(), this.unitList,
R.layout.unit_list_item, new String[] { TAG_OWNER, TAG_NAME,
TAG_CONTENT }, new int[] { R.id.unitsCol1, R.id.unitsCol2,
R.id.unitsCol3 });
fragment.setListAdapter(adapter); // Set the adapter to the listFragment
Then for the on click listener, I simply override it in the fragment:
public class UnitsListFragment extends ListFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Fetch stuff here
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
String type = l.getItemAtPosition(position).getClass().toString();
Log.d("Item type was", type);
// THIS IS NEVER INVOKED :(
};
}
I have tried so many different things, but maybe you guys can see a simple fix to this, something that I might have overlooked.
Any help would be greatly appreciated! Thanks!
Remove your scollview in layout or define it as not focusable then try again