I am creating an android application with custom OnClickListener that’s defined in it’s own class.
The problem is when I want to create Indeterminate Progress Bar in title bar that will be started when the onClick method will be called.
I can’t setProgressBarIntederminateVisibility from MyOnClickListener class because it’s not the main activity, and I can’t request getParent because it’s not a activity.
public class MyOnClickListener implements OnClickListener {
private message;
public MyOnClickListener(Context context,TextView mstatus, TextView message) {
this.message=message;
}
@Override
public void onClick(View v) {
int id = v.getId();
switch (id){
case R.id.next:
this.message.setText(GetValue.getNextValue());//during this operation I want progress bar to be spinning
Log.v("MyOnClickListener", "next pressed");
break;
case R.id.prev:
this.message.setText(GetValue.getPrevValue());
Log.v("MyOnClickListener","prev pressed");
break;
case R.id.last:
this.message.setText(GetValue.getlastvalue());
break;
default: break;
}
}
}
What Can I do?
Typically, you’d have this as an inner class of your Activity, which then has an implicit reference to your “outer” Activity class. As an alternative, you can of course pass a reference to your Activity when you construct your listener object.