Android 单击gridView适配器项

Android 单击gridView适配器项,android,gridview,Android,Gridview,我有一个使用此自定义适配器的gridView: package com.example.awesomefilebuilderwidget; IMPORTS public class GridViewAdapter extends BaseAdapter { private Context Context; // Keep all Images in array list public ArrayList<Integer> drawables = new ArrayList<

我有一个使用此自定义适配器的gridView:

package com.example.awesomefilebuilderwidget;

IMPORTS

public class GridViewAdapter extends BaseAdapter {
private Context Context;

// Keep all Images in array list
public ArrayList<Integer> drawables = new ArrayList<Integer>();

CheckBox mCheckBox=null;

// Constructor
public GridViewAdapter(Context c){
    Context = c;
    Log.d("GridViewAdapter", "Constructor is set");

    drawables.add(R.drawable.add_button);
    Log.d("GridViewAdapter", "add_button added");

    drawables.add(R.drawable.pattern1);
    Log.d("GridViewAdapter", "pattern1 added");

    drawables.add(R.drawable.pattern2);
    Log.d("GridViewAdapter", "pattern2 added");

    drawables.add(R.drawable.trashcan);
    Log.d("GridViewAdapter", "trashcan added");

    drawables.add(R.drawable.ic_launcher);
    Log.d("GridViewAdapter", "ic_launcher added");
}

public void setCheckBox(CheckBox checkbox){
    mCheckBox=checkbox;
}

@Override
// How many items are in the data set represented by this Adapter
public int getCount() {
    return drawables.size();
}

@Override
// Get the data item associated with the specified position in the
// data set
public Object getItem(int position) {
    return drawables.get(position);
}

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

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // Try to reuse the views
    ImageView view = (ImageView) convertView;
    boolean checked = (mCheckBox==null)?false:(((CheckBox)  mCheckBox).isChecked());
    // if convert view is null then create a new instance else reuse it
    if (view == null) {
        view = new ImageView(Context);
        Log.d("GridViewAdapter", "new imageView added");
        view.setId(R.id.iconImageView_id);
    }
    view.setImageResource(drawables.get(position));
    view.setScaleType(ImageView.ScaleType.CENTER_CROP);
    view.setLayoutParams(new android.widget.GridView.LayoutParams(70, 70));
    view.setTag(String.valueOf(position));
    return view;
}

}

如果我这样做,如何设置它,使OnItemClickListener仅对OnItemClickListener中的
add\u按钮执行特定操作?

在OnItemClickListener中,放置一条If语句以检查单击的项是否为add\u按钮。如果是的话,就采取行动

android.widget.GridView gridView = (android.widget.GridView) findViewById(R.id.GRIDVIEW1);

    // Instance of Adapter Class
    GridViewAdapter mGridViewAdapter= new GridViewAdapter(this);
    gridView.setAdapter(mGridViewAdapter);
    CheckBox mCheckBox = (CheckBox) findViewById(R.id.addCheckbox);
    mGridViewAdapter.setCheckBox(mCheckBox);

   gridView.setOnItemClickListener(this);