Custom ListAdapter with ViewHolder Pattern I wrote this class for a custom list adapter for my list view. I use the view holder pattern to make the list view move smoother.

Could anyone advice tell me if I did something wrong, or some way to refine my code?

Example: defining my views. Is there way to make it faster?

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.validate.R;

import java.util.List;

/**
 * Created by Mina on 30/06/2015.
 */
public class vault_listadapter extends BaseAdapter {
    private List&lt;Vault_item_class&gt; vault_items;
    private Context context;
    private LayoutInflater inflater;

    TextView merchantName_tv, voucherType_tv, voucherName_tv, voucherDetail_tv, voucherValue_tv,
            issueDate_tv, expiryDate_tv, voucherCode_tv;
    ImageView barcode_imageview;

    public void vault_listadapter(Context context, List&lt;Vault_item_class&gt; vault_items) {
        this.context = context;
        this.vault_items = vault_items;
        this.inflater = LayoutInflater.from(context);

    }

    @Override
    public int getCount() {
        return vault_items.size();
    }

    @Override
    public Vault_item_class getItem(int position) {
        return vault_items.get(position);
    }

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

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

        if (convertView == null) {
            convertView = inflater.inflate(R.layout.vault_item, null, false);
            holder = new ViewHolder();

            holder.merchantName_tv = (TextView) convertView.findViewById(R.id.merchantName_id);
            holder.voucherName_tv = (TextView) convertView.findViewById(R.id.voucherName_id);
            holder.voucherType_tv = (TextView) convertView.findViewById(R.id.voucherType_id);
            holder.voucherDetail_tv = (TextView) convertView.findViewById(R.id.voucherDetails_id);
            holder.voucherValue_tv = (TextView) convertView.findViewById(R.id.voucherVaule_id);
            holder.issueDate_tv = (TextView) convertView.findViewById(R.id.issueDate_id);
            holder.expiryDate_tv = (TextView) convertView.findViewById(R.id.expiryDate_id);
            holder.voucherCode_tv = (TextView) convertView.findViewById(R.id.voucherCode_id);

            holder.barcode_imageview = (ImageView) convertView.findViewById(R.id.barcodeimg_id);

            convertView.setTag(holder);
        } else {
           holder = (ViewHolder) convertView.getTag();
        }


        return convertView;
    }

    static class ViewHolder {
        TextView merchantName_tv, voucherType_tv, voucherName_tv, voucherDetail_tv, voucherValue_tv,
                issueDate_tv, expiryDate_tv, voucherCode_tv;
        ImageView barcode_imageview;
    }
}
Here is a complex example for your case:


  List Adapter with ViewHolder Pattern


Note:


Never use a parameter as a variable (parameters shouldn't be modified!) 
I like to use an underscore at the beginning of global fields (variables, objects) names to better show their scope.
You should make a class name without any special characters and beginning with an uppercase letter.
Try to get context from the closest possible parameter (as in my example from the parent of the getView() method).
The class constructor is defined without a return type (with the same name as the class name and any parameter if you desire)!
For later data changes in the adapter, you can define a method to add items to the list (as an example).