我在这里阅读了很多问题,但无法弄清问题是什么.
我正在为Android编写一个现场服务应用程序.在其中一个活动(MyActivity.java)中,我有两个按钮:Start和Stop.
当现场工作人员按下启动时,我需要使用GPS获取当前位置并及时将其发送到服务器(比如默认为5分钟,这里我将其设置为20秒进行测试).客户希望看到工人花多长时间在交通上,我的城市(伊斯坦布尔)的交通是一团糟.
我的活动中有一个AlarmManager,当按下开始按钮时,警报被设置AlarmManager.setRepeating()为启动服务(ServiceClass.java).
Intent intent = new Intent (MyActivity.this, ServiceClass.class);
mPendingIntent = PendingIntent.getService(MyActivity.this, 0, intent,
PendingIntent.FLAG_CANCEL_CURRENT);
mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
mAlarmManager.setRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), 20*1000,
mPendingIntent);
Run Code Online (Sandbox Code Playgroud)
我用停止按钮取消闹钟.
它完美地运行到此为止,服务开始了.它onCreate(),onStart()并且onDestroy()方法执行.但我无法得到这个位置.我没有在真正的设备上工作,所以我使用DDMS发送位置.但应用程序跳过该步骤并打印我的位置的经度和纬度为Lon:0 Lat:0.
这是服务中的代码:
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
Log.d("Testing", "Service got started, calling location updates:");
mLocationManager.requestSingleUpdate(mCriteria, mLocationListener,
getMainLooper());
Log.i("TESTING LOCATION UPDATE: LOCATION:", "\nLat:" + mLatitude +
" Lon:" + mLongitude);
stopSelf(startId);
Log.d("Testing", "Service Stopped!");
Run Code Online (Sandbox Code Playgroud)
最后,这是我的LocationListener:
mLocationListener = new LocationListener() {
@Override
public …Run Code Online (Sandbox Code Playgroud) 我写了一个自定义对话框,它工作得很好.
public class GalleryAlertDialog extends Dialog {}
Run Code Online (Sandbox Code Playgroud)
在课堂上,我用班级来称呼班级
dialog.show();
Run Code Online (Sandbox Code Playgroud)
我希望实现这个目标:

我需要对话框上的按钮,就像这样.
但是,这就是我得到的:

这是布局xml的部分,我在其中声明布局和其中的按钮:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical">
<LinearLayout
android:id="@+id/ll_buttonContainer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dip"
android:gravity="right"
android:orientation="vertical" >
<ImageButton
android:id="@+id/btn_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector_button_popupclose"
android:contentDescription="TODO"
android:tag="btn_close" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_pagerContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/ll_buttonContainer"
android:layout_marginTop="80dip"
android:background="@color/white" />
<ToggleButton
android:id="@+id/tbFavorite"
android:layout_width="35dip"
android:layout_height="35dip"
android:layout_gravity="bottom|right"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dip"
android:background="@drawable/selector_check"
android:checked="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:textOff=""
android:textOn="" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#ff212121"
android:gravity="center_vertical"
android:orientation="horizontal" > …Run Code Online (Sandbox Code Playgroud) android transparent android-layout android-alertdialog android-dialog