Search code examples
androidandroid-activityseekbar

how to get a reference to the activity class inside an actionhandler


This is my code:

     seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){


   public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    // TODO Auto-generated method stub
    seekBarValue.setText(String.valueOf(progress));
    imageLoader.DisplayImage(imageArray[progress], <<NEED A REFERENCE TO THE ACTIVITY CLASS>>, movieFrame);
   }
    }

The problem here is i am unable to get a reference to the activity class the seekBar is inside. Can anyone kindly help me out ? Thanks.


Solution

  • this should do it, if i have got your question right..

    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
    
    
           public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            // TODO Auto-generated method stub
            seekBarValue.setText(String.valueOf(progress));
            imageLoader.DisplayImage(imageArray[progress], <<NEED A REFERENCE TO THE ACTIVITY CLASS>>, movieFrame);
    
        Activity a = YourActivityname.this;
           }
            }
    

    if nothing is working out, then create a instance variable of type Activity and initialise it in Activity's onCreate method, something like below.

    Class A extends Activity{
    
    private Activity instance;
    @Override
            protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(Bundle savedInstanceState);
    
    instance = A.this;
    }
    
    }