I've been struggling like crazy to add a button below a ListView
of a ListFragment
, I've followed most suggestions of the questions How to show a button at the end of an Android ListView, Android Layout with ListView and Buttons and Displaying the button at the end of the ListView with Linear Layout. I just havent tried yet the ListView#addFooterView() yet as I would prefer not to add the button programmatically.
I have the impression that the reason why theirs solutions work for them and not for me is due to the fact that my layout refers to a fragment layout under an activity that has a tab action bar.
As you can see in the picture, the shadow of the linear layout in which my button is part of can be seen overridden by the navigation bar. And the amount overridden resembles the height of the tabs
My fragment layout is the one below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/service_notif_list_fragment"
>
<TextView
android:id="@+id/serviceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="2.0"
android:drawSelectorOnTop="false"/>
<TextView android:id="@id/android:empty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No data"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
style="@android:style/ButtonBar">
<Button
android:id="@+id/delServiceButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|left"
android:text="Delete Service" />
</LinearLayout>
</LinearLayout>
And my fragment code does not do anything exceptional, except using Loaders to load the list data from the db
public class ServiceSpecifNotListFragment extends ListFragment implements
LoaderCallbacks<Cursor> {
Button deleteServiceButton = null;
String serviceUri;
String servName;
TextView serviceName = null;
private NotificationCursorAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] uiBindFrom = { ...};
int[] uiBindTo = { ... };
getLoaderManager().initLoader(Constants.SERVICE_SPECIFIC_LIST_LOADER, null, this);
adapter = new NotificationCursorAdapter(
getActivity().getApplicationContext(), R.layout.service_specifc_notif_row,
null, uiBindFrom, uiBindTo,
CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
setListAdapter(adapter);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.service_notif_list_fragment, container, false);
serviceName = (TextView) rootView.findViewById(R.id.serviceName);
serviceName.setText(servName); // the name is set in the onCreateLoader
deleteServiceButton = (Button) rootView.findViewById(R.id.delServiceButton);
deleteServiceButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO
}
});
return rootView;
}
@Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle bundleArg) {
String[] projection = { ...};
Bundle arg = this.getArguments();
CursorLoader cursorLoader = new CursorLoader(getActivity(),
NotificationContentProvider.CONTENT_URI, projection, selection, selectionArgs, NotificationData.SERVER_TIME + " DESC");
return cursorLoader;
}
else{
Log.d(TAG, "failed to retrieve service name");
return null;
//TODO: find a destroy self
}
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
adapter.swapCursor(cursor);
}
@Override
public void onLoaderReset(Loader<Cursor> arg0) {
adapter.swapCursor(null);
}
@Override
public void onDestroyView(){
super.onDestroyView();
Log.d(TAG, "on destroy view");
}
@Override
public void onDestroy(){
super.onDestroy();
Log.d(TAG, "on destroy");
}
}
If needed, I can post the code of the main activity, and on...