How to use buttons from different xml files in one class
<p>I have a listview with multiple items and one button to start a new activity. I'm getting Null Pointer Exception when I run my app. How and where shoud I set the OnClickListener to run properly?</p>

<p>Also, how can I pass with Intent the arraylist named listaIngrediente?</p>

<p>Here is my code
main_activity.xml</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.example.radu.fridgecheck.MainActivity"
    android:orientation="vertical"&gt;

    &lt;ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"&gt;
    &lt;/ListView&gt;

    &lt;Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/find_recipies"
        android:id="@+id/find"
        android:layout_weight="0"/&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p>list_item.xml</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="6dip" &gt;

    &lt;CheckBox
        android:id="@+id/checkBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:focusable="false"
        android:focusableInTouchMode="false"/&gt;

    &lt;TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/checkBox"
        android:layout_alignBottom="@+id/checkBox"
        android:layout_toRightOf="@+id/checkBox"
        android:text="TextView" /&gt;  
&lt;/RelativeLayout&gt;
</code></pre>

<p>Adapter</p>

<pre><code>    public class Adapter extends ArrayAdapter&lt;Ingredient&gt; {

    public LayoutInflater inflater;
    public ArrayList&lt;Ingredient&gt; listaIngrediente;
    ArrayList&lt;String&gt; ingredienteDisponibile;
    private Activity activity;


    public Adapter(Activity activity, int textResourceId, ArrayList&lt;Ingredient&gt; ingrediente) {
        super(activity, textResourceId, ingrediente);
        this.activity=activity;
        this.listaIngrediente=ingrediente;

        try {
            inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public int getCount() {
        return listaIngrediente.size();
    }

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

    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;

        if (convertView == null) {
            v = inflater.inflate(R.layout.list_item, null);
        }

        final Ingredient ingredients = getItem(position);

        final TextView display_ingredients = (TextView) v.findViewById(R.id.name);
        display_ingredients.setText(ingredients.getNameI());

        final CheckBox checkBox = (CheckBox) v.findViewById(R.id.checkBox);

        ListView listView = (ListView) v.findViewById(R.id.listView1);
        Button button = (Button) v.findViewById(R.id.button);
        listView.addFooterView(button);

        Button find = (Button) v.findViewById(R.id.find);
        find.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent(getContext(), ShowRecipes.class);
                Bundle args = new Bundle(); /// nu reusesc sa transfer obiectele
                args.putSerializable("ARRAYLIST",listaIngrediente);
                i.putExtra("BUNDLE",args);
                activity.startActivity(i);
            }
        });

        v.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(!ingredients.isSelected()) {
                    checkBox.setChecked(true);
                    ingredients.setSelected(true);
                }
                else{
                    checkBox.setChecked(false);
                    ingredients.setSelected(false);                  
                }
            }
        });
        return v;
    }
}
</code></pre>