我有一个OnClickListener
我的GridView
:
public class MyOnClickListener implements View.OnClickListener {
private final int position;
public MyOnClickListener(int position)
{
this.position = position;
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch(position){
case 0:
Intent a = new Intent(v.getContext(), Weapons.class);
v.getContext().startActivity(a);
break;
//case 1, 2, etc...
}
}
我如何在另一个班级中使用它?我让我的Category
班级这样做:
GridView gridview = (GridView) findViewById(R.id.categoryGrid);
gridview.setAdapter(new ButtonAdapter(this));
gridview.setOnClickListener(new MyOnClickListener(this));
当我这样做时,该(new MyOnClickListener(this));
行带有下划线,表示我需要更改public MyOnClickListener(int position)
为public MyOnClickListener(Category category)
.
我怎样才能解决这个问题?