Add empty item to the end of ListView

1

I have FloatingActionButton in the lower right corner of my screen, and when it reaches the end of ListView , it sits on top of a button. I would like to add an empty item at the end of ListView so that when it reaches the end of the list it does not happen.

I want to do the same thing in Gmail:

Whitespace appears only when it reaches the last item. I'm using adapter for my ListView:

public class AdaptadorProdutosSemelhantes extends BaseAdapter {
    String[] nomeprod,estabelecimentoprod,precoprod;
    int[] imgprod;
    Context context;
    LayoutInflater inflater = null;

    public AdaptadorProdutosSemelhantes(int[] imgprod, String[] nomeprod, String[] estabelecimentoprod, String[] precoprod, Context context) {
        this.nomeprod = nomeprod;
        this.estabelecimentoprod = estabelecimentoprod;
        this.precoprod = precoprod;
        this.context = context;
        this.imgprod = imgprod;
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return nomeprod.length;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public class Holder{
        ImageView imgproduto;
        TextView nomeproduto,precoproduto,estabelecimentoproduto;
        Button vertodas;
        RatingBar ratingBar;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder h = new Holder();
        View v = inflater.inflate(R.layout.lista_produtos_semelhantes,null);
        h.imgproduto = (ImageView) v.findViewById(R.id.imgprodsemelhante);
        h.nomeproduto = (TextView) v.findViewById(R.id.nomeprodsemelhante);
        h.precoproduto= (TextView) v.findViewById(R.id.precoprodsemelhante);
        h.estabelecimentoproduto = (TextView) v.findViewById(R.id.infosupprodsemelhante);
        h.vertodas = (Button) v.findViewById(R.id.vertodasofertas);
        h.ratingBar = (RatingBar) v.findViewById(R.id.ratingBarprodsemelhante);
        h.imgproduto.setImageResource(imgprod[position]);
        h.nomeproduto.setText(nomeprod[position]);
        h.precoproduto.setText(precoprod[position]);
        h.estabelecimentoproduto.setText(estabelecimentoprod[position]);

        h.vertodas.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        return v;
    }
    
asked by anonymous 18.08.2016 / 16:47

1 answer

2

To solve your problem, there are several possibilities. Sometimes the action button is not vital enough that it needs to be seen all the time. In some cases, hiding it while scrolling down can make a lot of sense.

Updated Google guidelines show a version - > Floating action button - to animate the button entering and exiting.

Now,alsoforyourcase,youcanuse ListView # addFooterView () to add a display View at the bottom of the ListView.

You can try this by creating a classe Viewtypes :

private class Viewtypes{
        public static final int Header = 1;
        public static final int Normal = 2;
        public static final int Footer = 3;
}

Then on your Adapter :

@Override
public int getItemViewType(int position) {

    if(items.get(position).isHeader)
        return Viewtypes.Header;
    else if(items.get(position).isFooter)
        return Viewtypes.Footer;
    else
        return Viewtypes.Normal;

}

GetView:

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
    View rowView;

    switch (position)
    {
        case Viewtypes.Normal:
            rowView=LayoutInflater.from(parent.getContext()).inflate(R.layout.normal, parent, false);
            break;
        case Viewtypes.Header:
            rowView=LayoutInflater.from(parent.getContext()).inflate(R.layout.header, parent, false);
            break;
        case Viewtypes.Footer:
            rowView=LayoutInflater.from(parent.getContext()).inflate(R.layout.footer, parent, false);
            break;
        default:
            rowView=LayoutInflater.from(parent.getContext()).inflate(R.layout.normal, parent, false);
            break;
    }
    return new ViewHolder (rowView);
}

Good luck!

    
18.08.2016 / 17:57