title: Listview button click listener is not working
body: <p>I'm using an <code>adapter</code> class to set values for my items. For each item there is a <code>+</code> and a <code>-</code> button. I have a <code>foodActivity</code> java class, <code>activity_food</code> layout for the java class and a <code>list_view_layout</code> for the lists. I have initialized the <code>+</code> and <code>-</code> buttons inside my activity class. When the <code>activity_food</code> starts, the app crashes.</p>
  
  <p><img src="https://i.stack.imgur.com/3VKtB.jpg" alt="This is my item list image"></p>
  
  <p><strong>plus, minus and edittext in list_view_layout -</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;Button
      android:id="@+id/minus"
      android:layout_width="35dp"
      android:layout_height="35dp"
      android:layout_below="@+id/foodname"
      android:layout_toEndOf="@+id/foodpic"
      android:text="-"
      android:textSize="12sp" /&gt;
  
  &lt;EditText
      android:id="@+id/quantity"
      android:layout_width="25dp"
      android:layout_height="30dp"
      android:layout_below="@+id/foodname"
      android:layout_toEndOf="@+id/minus"
      android:ems="10"
      android:inputType="number"
      android:textAlignment="center"
      android:background="@drawable/edittextbackground"
      android:text="0" /&gt;
  
  &lt;Button
      android:id="@+id/plus"
      android:layout_width="35dp"
      android:layout_height="35dp"
      android:layout_alignTop="@+id/quantity"
      android:layout_toEndOf="@+id/quantity"
      android:text="+"
      android:textSize="12sp" /&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>activity_food layout -</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="com.res.easyorder.foodActivity"&gt;
  
      &lt;ListView
          android:id="@+id/listview"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentStart="true"
          android:layout_alignParentTop="true"
          android:divider="#ffff"
          android:dividerHeight="5dp"/&gt;
  &lt;/RelativeLayout&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>My adapter class -</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>package com.res.easyorder;
  
  
  import android.content.Context;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  import java.util.ArrayList;
  import java.util.zip.Inflater;
  
  public class MyAdapter extends ArrayAdapter&lt;item&gt; {
  
      int q_ty = 0;
      ArrayList&lt;item&gt; foodlist = new ArrayList&lt;&gt;();
  
      public MyAdapter(Context context, int textViewResourceId, ArrayList&lt;item&gt; objects){
  
          super(context, textViewResourceId, objects);
          foodlist = objects;
      }
  
      @Override
      public int getCount(){
  
          return super.getCount();
      }
  
      @Override
      public View getView(final int position, View convertView, ViewGroup parent){
  
          View v = convertView;
          LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          v = inflater.inflate(R.layout.list_view_layout, null);
  
          ImageView foodpic = (ImageView) v.findViewById(R.id.foodpic);
          TextView foodname = (TextView) v.findViewById(R.id.foodname);
          TextView foodprice = (TextView) v.findViewById(R.id.foodprice);
          Button plus = (Button) v.findViewById(R.id.plus);
          final EditText quantity = (EditText) v.findViewById(R.id.quantity);
          Button minus = (Button) v.findViewById(R.id.minus);
  
          plus.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  item item = getItem(position);
                  q_ty = Integer.parseInt(item.getQuantity());
                  q_ty = q_ty + 1;
                  quantity.setText("" +q_ty);
              }
          });
  
  
          foodname.setText(foodlist.get(position).getFoodName());
          foodpic.setImageResource(foodlist.get(position).getFoodImage());
          foodprice.setText("BDT: " +foodlist.get(position).getFoodPrice());
          quantity.setText(foodlist.get(position).getQuantity());
  
          return v;
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>foodActivity java code. Plus minus onclicklistener is being commented -</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>package com.res.easyorder;
  
  import android.content.Intent;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.ListView;
  import android.widget.Toast;
  
  import com.google.firebase.auth.FirebaseAuth;
  
  import java.util.ArrayList;
  
  public class foodActivity extends AppCompatActivity {
  
      private String type = null;
      int quantity = 0;
  
      private Button plus, minus;
      private EditText q_ty;
  
      ListView simplelist;
      ArrayList&lt;item&gt; foodlist = new ArrayList&lt;&gt;();
      private FirebaseAuth firebaseAuth;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_food);
  
          firebaseAuth = FirebaseAuth.getInstance();
          simplelist = (ListView) findViewById(R.id.listview);
  
          plus = (Button) findViewById(R.id.plus);
          minus = (Button) findViewById(R.id.minus);
          q_ty = (EditText) findViewById(R.id.quantity);
  
          type = getIntent().getExtras().getString("type");
  
          if(type.equals("breakfast"))
          {
              foodlist.add(new item("Rooti",R.drawable.ruti,5));
              foodlist.add(new item("Parata",R.drawable.porata,8));
              foodlist.add(new item("Tandoor",R.drawable.tandoor,15));
              foodlist.add(new item("Vegetable",R.drawable.sodji,10));
              foodlist.add(new item("Daal",R.drawable.dal,10));
              foodlist.add(new item("Omelet",R.drawable.dimvaji,15));
              foodlist.add(new item("Singara",R.drawable.singara,8));
              foodlist.add(new item("Samosa",R.drawable.samosa,10));
              foodlist.add(new item("Puri",R.drawable.puri,5));
  
          }
          
  
          MyAdapter myAdapter = new MyAdapter(this,R.layout.list_view_layout,foodlist);
          simplelist.setAdapter(myAdapter);
  
          /*plus.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
  
                  //quantity = quantity + 1;
                  //q_ty.setText(""+quantity);
              }
          });
  
          minus.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
  
                  if (quantity==0)
                  {
                      //q_ty.setText(""+quantity);
                  }
  
                  else if (quantity&gt;0)
                  {
                      quantity = quantity - 1;
                      //q_ty.setText(""+quantity);
                  }
              }
          });*/
      }
  
     
  }</code></pre>
  </div>
  </div>
  </p>