I have an ArrayList of Buttons where my OCL needs to know which index I has been pressed. The plan is something like this:
MyOnClickListener onClickListener
set setOnClickListener
to Button as :
buttonList.get(i).setOnClickListener(new MyOnClickListener(i));
EDIT :
I need to finish an activity in myOCL, how would I do that?
for finishing Activity on Button Click from non Activity class you will need to pass Activity Context to your custom OnClickListener as :
buttonList.get(i).setOnClickListener(new MyOnClickListener(i, Your_Current_Activity.this));
and change the Constructor of your custom OnClickListener class to :
int index;
Context context;
public MyOnClickListener(int index,Context context)
{
this.index = index;
this.context=context;
}
@Override
public void onClick(View arg0) {
// now finish Activity as\
context.finish();
// OR
// ((Activity)context).finish();
}