当前位置: 代码迷 >> Android >> 请问一段代码,finish()出错
  详细解决方案

请问一段代码,finish()出错

热度:205   发布时间:2016-04-28 00:36:08.0
请教一段代码,finish()出错,
finish()报错,划红线,显示为The method finish() is undefined for the type new View.OnClickListener(){},求大神帮忙下,在代码的最后几行
operatorClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.btn_persona_edit:
if(operatorIndex == 1){
                    SetOperatorBtn(0);
                    hcType=2;
                    hcEdit=false;
                    homeState=false;
                }
if(operatorIndex == 2){
                    SetOperatorBtn(0);
                    hcType=2;
                    hcEdit=false;
                    companyState=false;
                }
                    if(operatorIndex == 3){
                        SetOperatorBtn(0);
                        return;
                    }
                    SetOperatorBtn(3);
break;

case R.id.btn_persona_del:
if(operatorIndex == 1){
                    SetOperatorBtn(0);
                    hcType=2;
                    hcEdit=false;
                    homeState=false;
                }
if(operatorIndex == 2){
                    SetOperatorBtn(0);
                    hcType=2;
                    hcEdit=false;
                    companyState=false;
                }
                    if(operatorIndex == 4){
                        SetOperatorBtn(0);
                        return;
                    }
                    SetOperatorBtn(4);
break;

case R.id.btn_persona_delall:
                    SetOperatorBtn(0);
                    if(gudieTextView != null&&ListItems.size()>0){
                        confirmDialog(getResources().getString(R.string.if_del_all), new ConfirmOperate()
                        {
                            @Override
                            public void operate()
                            {
                                if(R.id.layout_history == index){
                                    RecordsHelper.getInstance().deleteAllPois(RecordsHelper.HISTORY_HELPER);
                                    RecordsHelper.getInstance().queryAllPoi(RecordsHelper.HISTORY_HELPER, mPois);

                                }else{
                                    RecordsHelper.getInstance().deleteAllPois(RecordsHelper.FAVORITE_HELPER);
                                    RecordsHelper.getInstance().queryAllPoi(RecordsHelper.FAVORITE_HELPER, mPois);
                                }
                                ListItems.removeAll(ListItems);
                                setupListViews(mPersonaList, mPois,ListItems);
                            }
                        });
}
break;
case R.id.bottom_bar_back:
//这里报错
                                       //这样也不行Activity.this.finish();
finish();
break;

}
}
};
------解决思路----------------------
activity 名称.this.finish也不行么?
------解决思路----------------------
OnClickListener类中肯定没有finish方法,此方法是在Activity类中的,通过你外部的Activity.this.finish调用
------解决思路----------------------
你的这个OnClickListener的实例是在Activity实例化的么,要是不在Activity中,finish方法一定是没有定义的了,
------解决思路----------------------
引用:
Quote: 引用:

OnClickListener类中肯定没有finish方法,此方法是在Activity类中的,通过你外部的Activity.this.finish调用

不行啊。提示The method finish() is undefined for the type PersonalMode
finish是Activity类的方法,如果你的PersonMode不是Activity的子类,那肯定就没有finish方法
------解决思路----------------------
引用:
Quote: 引用:

Quote: 引用:

Quote: 引用:

OnClickListener类中肯定没有finish方法,此方法是在Activity类中的,通过你外部的Activity.this.finish调用

不行啊。提示The method finish() is undefined for the type PersonalMode
finish是Activity类的方法,如果你的PersonMode不是Activity的子类,那肯定就没有finish方法

应该是个fragment
fragment可以getActivity然后再调用finish方法