OnClickListener未触发

时间:2014-08-06 21:32:20

标签: android google-maps onclicklistener buttonclick

我正在尝试将onClickListener定义为一个按钮,但它不起作用......

这是听众:

    Button buttonVolta = (Button) findViewById(R.id.buttonVolta);

    buttonVolta.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if(isTestMarker()){
                Location devolveCoord = getCoordenadas();
                Intent intent = new Intent();  
                intent.putExtra("latitude", Double.toString(devolveCoord.getLatitude()));
                intent.putExtra("longitude", Double.toString(devolveCoord.getLatitude()));
                setResult(RESULT_OK,intent);
                TelaMapa.this.finishActivity(1);
            } else {
                Toast.makeText(TelaMapa.this, "Marque um ponto!", Toast.LENGTH_LONG);
            }
        }
    });

它位于创建地图的方法内,按钮位于地图下方......

     @Override
protected void onResume(){
    super.onResume();
    configureMap(); 
}


/**
 * function to load map. If map is not created it will create it for you
 * */
private void configureMap() {

...

}

这是方法调用和定义......

1 个答案:

答案 0 :(得分:0)

假设您需要完成当前活动,则应该只调用finish()而不是 TelaMapa.this.finishActivity(1);finishActivity用于完成当前活动检查https://developer.android.com/reference/android/app/Activity.html#finishActivity(int)

启动的子活动