File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Android and the fly likes edit text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "edit text" Watch "edit text" New topic

edit text

egbai mmumene
Ranch Hand

Joined: Sep 18, 2012
Posts: 46
i have an implementation of an array adapter that displays data i would like to have an edit text widget at the end of the adapter where a user can add to the list i dont know where to add the code.should i add it in the layout xml after the other list propertie definitions
Steve Luke

Joined: Jan 28, 2003
Posts: 4181

It depends on how you want the list to function. You could create a view with a ListView (backed by your ArrayAdapter) with the text field underneath it. The text field would take up screen space and wouldn't scroll with the ListView, so it would 'always' be visible. Or you could subclass ArrayAdapter and make it return one more element than is really in the list and tell it to display the text field for that last extra element. In this scenario the text field is always at the end of the list, and scrolls with the rest of the elements.

The second approach takes more work. Minimally you have to override the getCount() and getView(int, View, ViewGroup) method. In the getCount() method, return super.getCount()+1 so the ArrayAdapter tells the AdapterView that there is an extra thing to display. Then, in the getView() method, if the position parameter is < super.getCount() then return super.getView(), otherwise return your text field, so normally the ArrayAdapter provides the same view as it normally would, but if it is displaying the last element, it would show your text field instead. I am not sure if you would need to modify other methods... depends on if add() uses getCount() at all. For getItem() methods, you should probably override that to do something better than the likely IndexOutOfBounds exception if you try to get the item for the last position. You could either return some non-value (see Null object) or make sure your OnItemSelectedListener knows not to try to get the last item out of the adapter.

egbai mmumene
Ranch Hand

Joined: Sep 18, 2012
Posts: 46
thanks alot
I agree. Here's the link:
subject: edit text
It's not a secret anymore!