位置经纬度未更新
Location latitude and longitude not updated
您好,我正在测试此代码,但在 startUpdatesButtonHandler()
和 stopUpdatesButtonHandler()
处我收到消息说这些代码从未使用过。我应该在哪里使用这些,我忘记了什么吗?我使用了上面链接的代码。
没有更新经纬度,这是因为没有使用开始和停止按钮吗?我必须刷新整个 activity 才能更新它。
// Locate the UI widgets.
mStartUpdatesButton = (Button) findViewById(R.id.start_updates_button);
mStopUpdatesButton = (Button) findViewById(R.id.stop_updates_button);
您需要在这两个按钮上设置 onClickListener
。
检查 main_activity.xml
文件,可能那里已经设置了 onClick
。然而,它在评论中说,你可以在代码中看到,如果已经进行了位置更改,startUpdatesButtonHandler(View view)
将不执行任何操作。
只需添加已接受的评论作为答案。您需要在 XML.
中添加设置它们
例如
<Button
...
android:onClick="startUpdatesButtonHandler"
android:text="@string/start_update" />
<Button
...
android:onClick="stopUpdatesButtonHandler"
android:text="@string/stop_update" />
您好,我正在测试此代码,但在 startUpdatesButtonHandler()
和 stopUpdatesButtonHandler()
处我收到消息说这些代码从未使用过。我应该在哪里使用这些,我忘记了什么吗?我使用了上面链接的代码。
没有更新经纬度,这是因为没有使用开始和停止按钮吗?我必须刷新整个 activity 才能更新它。
// Locate the UI widgets.
mStartUpdatesButton = (Button) findViewById(R.id.start_updates_button);
mStopUpdatesButton = (Button) findViewById(R.id.stop_updates_button);
您需要在这两个按钮上设置 onClickListener
。
检查 main_activity.xml
文件,可能那里已经设置了 onClick
。然而,它在评论中说,你可以在代码中看到,如果已经进行了位置更改,startUpdatesButtonHandler(View view)
将不执行任何操作。
只需添加已接受的评论作为答案。您需要在 XML.
中添加设置它们例如
<Button
...
android:onClick="startUpdatesButtonHandler"
android:text="@string/start_update" />
<Button
...
android:onClick="stopUpdatesButtonHandler"
android:text="@string/stop_update" />