启动新的活动,打开Goog​​le地图

时间:2012-02-13 15:14:55

标签: android map android-intent

我是Android的初学者。我在这里有这段代码:

public class GPS extends Activity implements OnClickListener
{
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);

        View getGPSButton=findViewById(R.id.get_GPS);
        getGPSButton.setOnClickListener(this);
        View aboutButton=findViewById(R.id.about_button);
        aboutButton.setOnClickListener(this);
        View exitButton=findViewById(R.id.exit_button);
        exitButton.setOnClickListener(this);
    }

    public void onClick(View v) 
    {
        switch (v.getId())
        {
          case R.id.get_GPS:
              Intent i = new Intent (this,getGPS.class);
              startActivity(i);
          case R.id.about_button:
            Intent j = new Intent(this, About.class);
            startActivity(j);
            break;
          case R.id.exit_button:
            System.exit(0);
            finish();
            break;
        }
    }
}

但getGPS课程从未开始。无论我按什么按钮,我都会看到关于课堂活动的信息。 我知道,我的错误是在Intent parapeters中。我应该在Intent(...)中写什么? getGPS功能通过GPS计算经度和纬度,然后在该坐标处打开Goog​​le地图。那个班级里的一切都还可以。 退出功能也不起作用。 System.exit(0)和finish()都不会产生任何影响,当我按下exit_button时它会打开关于类。

等待你的建议。谢谢。

1 个答案:

答案 0 :(得分:1)

//你错过了休息

case R.id.get_GPS:
    Intent i = new Intent (this,getGPS.class);
    startActivity(i);
    break;

//如果它的按钮允许这样做

Button getGPSButton=(Button)findViewById(R.id.get_GPS);
        getGPSButton.setOnClickListener(this);
        Button aboutButton=(Button)findViewById(R.id.about_button);
        aboutButton.setOnClickListener(this);
        Button exitButton=(Button)findViewById(R.id.exit_button);
        exitButton.setOnClickListener(this);
相关问题