1

我正在制作一个 android 应用程序,它使用 gps 来标记你的纬度/经度、速度等,但是当我尝试更改应用程序不再加载的字段时,有什么想法吗?加载的第一个页面是 MainActivity.java 但这只是一个加载应用程序然后使用的徽标屏幕

setContentView(R.layout.main_page);

加载我将用来做大部分应用程序的 MainPageActivity.Java 是代码,这里是 MainActivity.Java 的代码:

package com.aramis;

import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

public class MainActivity extends Activity implements Runnable {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    setContentView(R.layout.activity_main);
    new CountDownTimer(5000, 1000) {

         public void onTick(long millisUntilFinished) {

         }

         public void onFinish() {

                setContentView(R.layout.main_page);
            }
         }.start();
        }


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            NavUtils.navigateUpFromSameTask(this);
            return true;
    }
    return super.onOptionsItemSelected(item);
}
public void run() {
    // TODO Auto-generated method stub

}

public void GoToMap(View view) {

    setContentView(R.layout.map);
}
public void GoToOpt(View view) {

    setContentView(R.layout.options);
}
public void GoToStart(View view) {
    setContentView(R.layout.main_page);
}


}

这是 MainPageActivity.Java 的代码:

package com.aramis;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainPageActivity extends Activity {

/** Called when the activity is first created. */
EditText et_gpsLAT;
EditText et_gpsLONG;
ProgressDialog progressDialog;
Thread thread;
String info;
LocationManager mlocManager=null;
LocationListener mlocListener;
AlertDialog.Builder alert;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_page);
    et_gpsLAT=(EditText)findViewById(R.id.et_gpsLAT);
    et_gpsLONG=(EditText)findViewById(R.id.et_gpsLONG);
    mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    mlocListener = new MyLocationListener();            
    mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
    mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    Button btn_gps=(Button)findViewById(R.id.btn_gps);
    btn_gps.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
    mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
    if (mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        if(MyLocationListener.latitude>0 )
        {
                et_gpsLAT.setText("Latitude:  "
            + MyLocationListener.latitude
            + '\n');
                et_gpsLONG.setText("Longitude:  "
            + MyLocationListener.longitude);
            }
    }
}
}
);

}



@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main_page, menu);
    return true;
}
}

这是显示纬度/经度的页面副本:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/backrepeat"
android:gravity="center_horizontal"
android:orientation="vertical" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="20dp"
    android:text="@string/LatENG"
    tools:context=".MainActivity" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="20dp"
    android:text="@string/Long"
    tools:context=".MainActivity" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView2"
    android:layout_below="@+id/textView2"
    android:layout_marginTop="20dp"
    android:text="@string/Alt"
    tools:context=".MainActivity" />

<TextView
    android:id="@+id/textView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView3"
    android:layout_below="@+id/textView3"
    android:layout_marginTop="20dp"
    android:text="@string/Speed"
    tools:context=".MainActivity" />

<TextView
    android:id="@+id/TextView02"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/textView2"
    android:layout_alignParentRight="true"
    android:layout_marginRight="21dp"
    android:text="@string/Current_Lat"
    tools:context=".MainActivity" />

<TextView
    android:id="@+id/TextView01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/textView2"
    android:layout_alignBottom="@+id/textView2"
    android:layout_alignRight="@+id/TextView02"
    android:text="@string/Current_Long"
    tools:context=".MainActivity" />

<TextView
    android:id="@+id/TextView03"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/textView4"
    android:layout_alignRight="@+id/TextView01"
    android:text="@string/Current_Alt"
    tools:context=".MainActivity" />

<TextView
    android:id="@+id/textView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/textView4"
    android:layout_alignBottom="@+id/textView4"
    android:layout_alignRight="@+id/TextView03"
    android:text="@string/Current_Speed"
    tools:context=".MainActivity" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:onClick="GoToMap"
    android:text="@string/mapbtn" />

<Button
    android:id="@+id/Button01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:onClick="GoToOpt"
    android:text="@string/optbtn" />

<Button
    android:id="@+id/btn_gps"
    style="@style/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/textView5"
    android:layout_marginTop="33dp"
    android:text=" GPS " />

<EditText
    android:id="@+id/et_gpsLAT"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/btn_gps"
    android:layout_centerHorizontal="true"
    android:editable="false"
    android:ems="10" />

<EditText
    android:id="@+id/et_gpsLONG"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/et_gpsLAT"
    android:layout_below="@+id/et_gpsLAT"
    android:editable="false"
    android:ems="10" >

    <requestFocus />
</EditText>

<TextView
    android:id="@+id/tv_gps"
    style="@style/label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/btn_gps"
    android:layout_alignParentLeft="true"
    android:text="Location :" />

</RelativeLayout>

对此的任何帮助将不胜感激我已经坚持了一段时间了

4

0 回答 0