Q:

Android ListView Get row on button click

I have a custom adapter class for a listview and I want to be able to access the content of a specific row by clicking a button on it.  I tried to create a ViewHolder, but I get a NPE error when I try to click it. 
static class ViewHolder {
    TextView camera;
    TextView players;
    TextView max_players;
    ImageView privata;
    Button Buton;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {

    String variabile[] = getItem(position).split("\\s+");
    LayoutInflater linflater = LayoutInflater.from(getContext());
        View customView = linflater.inflate(R.layout.custom_row, parent, false);
        final ViewHolder holder = new ViewHolder();
        holder.camera = (TextView) customView.findViewById(R.id. Nume);
        holder.players = (TextView) customView.findViewById(R.id.players);
        holder.max_players = (TextView) customView.findViewById(R.id.max_players);
        holder.privata = (ImageView) customView.findViewById(R.id.privata);
        holder. Buton = (Button) customView.findViewById(R.id. Buton);
        holder.camera.setText(variabile[0]);
        if (! variabile[1].equals("true")) {
            parola = false;
            holder.privata.setVisibility(View. INVISIBLE);
        }
        holder.players.setText(variabile[2]);
        holder.max_players.setText(variabile[3]);
        room_id = variabile[4];
        nume = variabile[5];
        holder. Buton.setOnClickListener(new View. OnClickListener() {
            public void onClick(View v) {
                hash = new HashMap<String, String>();
                hash.put("name", nume);
                hash.put("room", room_id);
                if (intra) {
                    holder. Buton.setText("Iesi");
                    site = siteul + "/join";
                    intra = false;
                } else {
                    holder. Buton.setText("Intra");
                    site = siteul + "/leave";
                    intra = true;
                }
                new ATask().execute(site);
            }
        });
    return customView;
}

A:

When using the ViewHolder pattern, you should check if the convertView in null or has been created before, in the getView method, and after that use setTag and getTag methods.  like this :
    if (convertView == null) 
    {
        LayoutInflater linflater = LayoutInflater.from(getContext());
        convertView = linflater.inflate(R.layout.your_list_item_view, parent, false);
         viewHolder.textView = (TextView)convertView.findViewById([the id]);
         . 
         . 
         . 

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

