Make Part Of Listview`s Header-/footerview Selectable
I have a ListView with a custom footer set via list.addFooterView(getLayoutInflater().inflate(R.layout.list_footer_view, null, true), null,true); list_footer_view.xml looks like
Solution 1:
You should also call setItemsCanFocus(true) on ListView. So there are actually two things needed to be done:
- android:descendantFocusability="afterDescendants" for header and footer ViewGroups
- setItemsCanFocus(true) for the whole ListView (you may want to set android:focusable="false" and android:focusableInTouchMode="false" for the row ViewGroup
You may also need to set focusable="true" for your elements you need to be focusable. Here's an example:
poi_details_buttons.xml:
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:descendantFocusability="afterDescendants"android:orientation="vertical" ><Viewstyle="@style/Poi.DetailsSeparator" /><Buttonandroid:id="@+id/show_all_comments"style="@style/Poi.DetailsItem"android:drawableRight="@drawable/icon_forward"android:hint="@string/poi_details_show_all_comments"android:text="@string/poi_details_show_all_comments" /><Viewstyle="@style/Poi.DetailsSeparator" /><Buttonandroid:id="@+id/report_bug"style="@style/Poi.DetailsItem"android:drawableRight="@drawable/icon_forward"android:hint="@string/poi_details_report_bug"android:text="@string/poi_details_report_bug" /><Viewstyle="@style/Poi.DetailsSeparator" /></LinearLayout>
PoiFragment.java:
protected View createView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
list = (ListView) (ViewGroup) inflater.inflate(R.layout.poi_details, container, false);
// allow buttons in header/footer to receive focus (comment_row.xml has focusable=false// for it's element, so this will only affect header and footer)// note: this is not enough, you should also set android:descendantFocusability="afterDescendants"
list.setItemsCanFocus(true);
...
View buttonsView = inflater.inflate(R.layout.poi_details_buttons, null);
buttonsView.findViewById(R.id.show_all_comments).setOnClickListener(this);
buttonsView.findViewById(R.id.report_bug).setOnClickListener(this);
list.addFooterView(buttonsView, null, false);
return list;
}
Post a Comment for "Make Part Of Listview`s Header-/footerview Selectable"