开发者

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 cl开发者_运维问答ass the seekBar is inside. Can anyone kindly help me out ? Thanks.


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;
}

}


You can simply use:

MyActivity.this


try this instead of passing reference.

this.getParent()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜