At the moment there is a GridViewActivity, where the toolbar has a " + " button (which adds items to the gridView list).

public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.addPerson) { addPersonToAdapter(); } return super.onOptionsItemSelected(item); } 

The question is the following: is it possible to place a given "+" image (or some kind of xml file) at the top of my list, where by clicking on this element my elements are added so that the "+" image always moves to the right?

Found about a similar problem , but not quite open.

    1 answer 1

    1. do so that the getCount() in the adapter returns 1 more than it actually does.
    2. in getView() do something like

       //проверяем, если это последний элемент, то нужно показать кнопку "+" if(position == getCount - 1) { return new <тут создаем саму кнопку. инфлейтим из XML, создаем "вручную"...> } else { тут возвращаем View как обычно } 
    • at the moment, I get persons.size () in getCount; add to it + 1 chtoli? or will it just be enough to make changes to the getView () method? - Inkognito
    • one
      @Inkognito, yes, add +1. To return persons.size() + 1; . And change getView() - Vladyslav Matviienko
    • I do not understand a bit how to correctly declare a button after return new. I updated the question, where I indicated how at the moment I use the add button. - Inkognito
    • something like return adapter.getItem (position - 1); ? I'm confused at all ... - Inkognito
    • @Inkognito, getView () returns a View. You must make a return View that you want to display at this position. If this position should have a "+" button, then you need to make the return <кнопка "+"> , which you need to create yourself - Vladyslav Matviienko