任何人都可以告诉我这个程序的xmls

时间:2014-03-28 11:00:30

标签: android gps sms android-xml

(ANDROID GPS) 实际上我是android的新手,因为我是一名c ++程序员所以我在这个程序中面临一些困难,即取得android手机的gps location并将其作为sms发送给给定的数字。但是因为它是在java中所以请有人告诉我这个程序的不同XML是什么...我的意思是字符串和主要的xmls

package com.adzz.gps;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.location.Location; 
import android.location.LocationListener; 
import android.location.LocationManager;   
import android.content.Context; 
import android.telephony.SmsManager; 
import android.view.Gravity; 
import android.view.View; 
import android.widget.Button; 
import android.widget.TextView; 
import android.widget.Toast; 
import android.view.View.OnClickListener;     


public class MainActivity extends Activity { 
     String m; 

 @Override 
 protected void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState); 
 setContentView(R.layout.main); 
 LocationManager manager= (LocationManager) 
this.getSystemService(Context.LOCATION_SERVICE); 
 LocationListener listener =new LocationListener() { 
 @Override 

 public void onStatusChanged(String provider, int status, Bundle extras) { 
 // TODO Auto-generated method stub 

 } 

 @Override 
 public void onProviderEnabled(String provider) { 
 // TODO Auto-generated method stub 

 } 

 @Override 
 public void onProviderDisabled(String provider) { 
 } 
 @Override 
 public void onLocationChanged(Location location) { 
 final String phoneNumber="9453603045"; 

 double lat1=location.getLatitude(); 
 Double d1= new Double(lat1); 
 double longi1=location.getLongitude(); 
 Double d2=new Double(longi1); 
 m="latitude = "+ d1.toString() + "and latitude = "+ d2.toString(); 
 SmsManager smsManager = SmsManager.getDefault(); 
 smsManager.sendTextMessage(phoneNumber, null, m, null, null); 
 TextView lat= (TextView) findViewById(R.id.lat); 
 TextView longi=(TextView) findViewById(R.id.longi); 

 lat.setText("latitude = "+lat1); 
 longi.setText("longitude ="+longi1); 
 } 
 }; 
 manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 25, 
listener); 
 Button b= (Button) findViewById(R.id.button1); 
 b.setOnClickListener(new OnClickListener() { 

 @Override 
 public void onClick(View v) { 

 Toast toast=Toast.makeText(Main.this, m, 5000); 
 toast.setGravity(Gravity.CENTER, 0, 0); 
 toast.show(); 
 } 
 }); 
 } 

 @Override 
 public boolean onCreateOptionsMenu(Menu menu) { 
 // Inflate the menu; this adds items to the action bar if it is present. 
 getMenuInflater().inflate(R.menu.main, menu); 
 return true; 
 } 

}  

2 个答案:

答案 0 :(得分:0)

首先,您需要在res目录中的layout文件夹中创建main.xml。这是在Activity中加载的主要布局,在main.xml中使用两个TextView,其id为lat和longi。 main.xml如下所示。

<?xml version="1.0" encoding="utf-8"?>

<TextView
    android:id="@+id/lat"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="195dp"
    android:text="Lattitude" />

<TextView
    android:id="@+id/longi"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView2"
    android:layout_alignParentTop="true"
    android:layout_marginTop="82dp"
    android:text="Longitude" />

答案 1 :(得分:0)

   <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/lat"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp" />

        <TextView
            android:id="@+id/longi"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp" />

        <Button
            android:id="@id/button1"
            android:layout_gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>