2012-11-10 2 views
1

그래서 나는 사용자 위치를 얻고 토스트에 표시하려고합니다 ...하지만 전혀 작동하지 않습니다 ... 또한 토스트를 보여 주려고했지만 토스트를 보여 주려고했지만 작동하지 않습니다. 심지어 그 시간에 여기 getApplicationContext 내 코드토스트가 작동하지 않습니다

package com.example.alert; 

import com.example.alert.CurrentLocation.MyLocationListener; 

import android.app.Activity; 
import android.app.ListActivity; 
import android.content.Context; 
import android.content.Intent; 
import android.location.Location; 
import android.location.LocationListener; 
import android.location.LocationManager; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.ListView; 
import android.widget.Toast; 


public class ViewAlerters extends Activity{ 

private Button addButton; 
private Button removeButton; 
LocationManager lm=(LocationManager)getSystemService(Context.LOCATION_SERVICE); 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.view_alerters); 
    Toast.makeText(ViewAlerters.this,"Hello",Toast.LENGTH_SHORT).show(); 

    LocationListener ll=new MyLocationListener(); 
    //lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5*60*10000, 0, ll); 
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll); 
    setUpViews(); 

} 

private void setUpViews() { 
    Toast.makeText(getApplicationContext(),"Hello",Toast.LENGTH_SHORT).show(); 

    addButton = (Button) findViewById(R.id.add_button); 
    //alerterText = (TextView) findViewById(R.id.alert_list_text); 
    removeButton = (Button)findViewById(R.id.remove_button); 
    addButton.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      Intent intent = new Intent(ViewAlerters.this,AddAlerter.class); 
      startActivity(intent); 
     } 
    }); 

} 



/* Class My Location Listener */ 
public class MyLocationListener implements LocationListener 
{ 

    public void onLocationChanged(Location loc) 
    { 
     if(loc!=null) 
     { 
      double x; 


      String Text = "My current location is: " +"Latitud = " + loc.getLatitude() +"Longitud = " + loc.getLongitude(); 
     /* cr.moveToFirst(); 
      while(!cr.isAfterLast()) { 
       al.add(cr.getString(cr.getColumnIndex(dbAdapter.KEY_NAME))); //add the item 
       cr.moveToNext(); 
      }*/ 
     // lm.addProximityAlert(loc.getLatitude(), loc.getLongitude(), 10009,, intent) 

      //for loop, alerters retrieving one by one 
//  x= calcDistance(loc.getLatitude(),loc.getLongitude(),z,y); 
    //  if(x<1){ 
     //  Intent myIntent = new Intent(ViewAlerters.this,CallMode.class); 
      //  startActivity(myIntent); 
      } 

     } 

    public void onProviderDisabled(String provider) { 
     // TODO Auto-generated method stub 
     Toast.makeText(getApplicationContext(),"Gps Disabled - @From :Alert Me",Toast.LENGTH_SHORT).show(); 


    } 

    public void onProviderEnabled(String provider) { 
     // TODO Auto-generated method stub 
     Toast.makeText(getApplicationContext(),"Gps Enabled - @From :Alert Me",Toast.LENGTH_SHORT).show(); 

    } 

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

    } 
    } 


public double calcDistance(double latA, double longA, double latB, double longB) { 

    double theDistance = (Math.sin(Math.toRadians(latA)) * Math.sin(Math.toRadians(latB)) + Math.cos(Math.toRadians(latA)) * Math.cos(Math.toRadians(latB)) * Math.cos(Math.toRadians(longA - longB))); 
    return new Double((Math.toDegrees(Math.acos(theDistance))) * 69.09*1.6093); 
} 

}

+2

활동이 생성 되었습니까? – Flawyte

답변

0
Toast.makeText(ViewAlerters.this,"Hello",Toast.LENGTH_SHORT).show(); 
관련 문제