I currently have a class extending the ListActivity class. I need to add some static buttons above the list that are always visible. I tried to grab a ListView using getListView () from the class. Then I used addHeaderView (View) to add the layout to the top of the screen.
Header.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:id="@+id/testButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Income" android:textSize="15dip" android:layout_weight="1" /> </LinearLayout>
Before installing the adapter, do the following:
ListView lv = getListView(); lv.addHeaderView(findViewById(R.layout.header));
This leads to the fact that nothing happens with the ListView, except that it populates from my database. Buttons do not appear above it.
Another approach that I tried to add to the top of the ListView. However, when I did this, it successfully moved down, however, if I added something above, it moved the ListView. No matter what I do, it seems like I can't put a few buttons above the ListView when I used ListActivity.
Thanks in advance.
synic, I have tried your suggestion before. I tried it again for the sake of common sense, and the button did not appear. Below is the layout file for the activity and the code that I implemented in oncreate ().
// My listactivity I'm trying to add a title to
public class AuditActivity extends ListActivity { Budget budget; @Override public void onCreate(Bundle savedInstanceState) { Cursor test; super.onCreate(savedInstanceState); setContentView(R.layout.audit); ListView lv = getListView(); LayoutInflater infalter = getLayoutInflater(); ViewGroup header = (ViewGroup) infalter.inflate(R.layout.header, lv, false); lv.addHeaderView(header); budget = new Budget(this);
Layout.xml for activity:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ListView android:id="@android:id/list" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@android:id/empty" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/empty" /> </LinearLayout>
android header listactivity
crv Apr 12 '10 at 6:13 2010-04-12 06:13
source share