如何通过OnLongClickListener实现BackPressed函数

时间:2013-12-27 17:29:25

标签: android button onclicklistener onlongclicklistener

onClickListener是onBackPressed函数:

onback.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            onBackPressed();
        }
    });

您是否知道如何通过OnLongClickListener实现此功能?

2 个答案:

答案 0 :(得分:0)

是你的意思吗?

onback.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public void onLongClick(View v) {
            // TODO Auto-generated method stub
            onBackPressed();
            return false;
        }
    });

并导入:

import android.view.View.OnLongClickListener;

答案 1 :(得分:0)

onback.setOnLongClickListener(new OnLongClickListener() {

            @Override
            public boolean onLongClick(View arg0) {
                onBackPressed();
                //finish(); you can also call finish
                return false;
            }
});