Java - 从处理程序引用外部类

时间:2013-10-03 10:33:15

标签: java android multithreading inner-classes

我有一个名为Gradebook的顶级类,它通过一个包含匿名线程调用的匿名处理程序为Spinner设置事件处理程序

this.spin.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener(){

        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,long arg3){
            Gradebook.this.pd = ProgressDialog.show((Context)Gradebook.this, (CharSequence)"", (CharSequence)"Loading Grade Book...", true, true);
            Gradebook.this.gradecatitems.clear();
            new Thread(new Runnable() {
                    public void run() {
                       //I need to reference the top-most level class, GradeBook's members in here
                    }
            }).start();
        });

如何从我的线程中引用顶级类成员?请记住,我的线程已经是匿名类中的匿名类。

1 个答案:

答案 0 :(得分:4)

它看起来像这样.-

YourClassName.this