Want first Item in ListView to be a n"add new..." and then the rest of list from a DB cursor
Basically I want a list view that has all the data from a database but the first item in the view always being "add new session" or add new something. That takes the user to the entry form. The thing is my lists use a SimpleCursorAdapter that is set from a cursor like
myCursor = getSessions();
which would fill out myCursor with all the sessions from the database, and I would set the list adapter to:
myCursor = getSessions();
theSessions= new SimpleCursorAdapter(this.getListView().getContext(),
R.layout.session_row, myCursor, columns, to);
setListAdapter(theSessions);
This is fine and dandy, but I don't know how to make that first element not part 开发者_开发百科of the cursor and its own "add new..." button essentially. Is there any way to do this or am I going about this wrong?
Example list would be:
"Add new customer..."
"Bob"
"Matt"
"Mike"
Where the names are from the database table of customers, and the add new customer is just part of that list that when clicked launches a new activity to add a new customer. The list view specifically I want this for is in another layout that has other information above the actual list of items.
Tried the header view, but not sure if its selectable this way (cannot set the true using this constructor), and its hard to tell one can even touch this, it looks just like text anyway to add borders to my list view?
EDIT:
ListView listView = (ListView)v.findViewById(R.id.session_list);
TextView sessionLabel = new TextView(mContext);
sessionLabel.setText("Add new session...");
listView.addHeaderView(sessionLabel);
Have you considered myListView.addHeaderView()
Use the Header to add your column view.
精彩评论