代码之家  ›  专栏  ›  技术社区  ›  Albert Sanchez Guerrero

烤在另一个类调用的活动中创建的祝酒词不起作用

  •  0
  • Albert Sanchez Guerrero  · 技术社区  · 7 年前

    我创建“GPsLocation”活动的方法是“TornosAdapter”,代码如下

     holder.torn_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast toast = Toast.makeText(c, "Puerta:" + t.getNumero_puerta() + "\nGeolocation: " + t.getGeolocation(), Toast.LENGTH_LONG);
                //localizacion gps
                Log.d(TAG,"Pasa a crear el intent");
                //Here I create GpsLocation
                Intent intent = new Intent(v.getContext(), GpsLocation.class);
                toast.show();
            }
        });
    

    我用void方法定义GpsLocation活动的类,这些方法不起作用

        package com.gpasport.controlaccesos.controlaccesos;
    import android.app.Activity;
    import android.content.Context;
    import android.location.Location;
    import android.location.LocationListener;
    import android.location.LocationManager;
    import android.os.Bundle;
    import android.widget.Toast;
    import android.util.Log;
    
    
    /**
     * Created by asanchez on 26/09/2017.
     */
    
    public class GpsLocation extends Activity {
    
        private static final String TAG = MainActivity.class.getSimpleName();
        /**
         * Called when the activity is first created.
         */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            Log.d(TAG,"GpsLocation creating bundle activity");
            super.onCreate(savedInstanceState);
            //setContentView(R.layout.main);
            LocationManager milocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            LocationListener milocListener = new MiLocationListener();
            milocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, milocListener);
        }
    
        public class MiLocationListener implements LocationListener {
            public void onLocationChanged(Location loc) {
                loc.getLatitude();
                loc.getLongitude();
                /*Prueba para imprimir la latiud por log*/
                Log.i(TAG,Double.toString(loc.getLatitude()));
                String coordenadas = "Mis coordenadas son: " + "Latitud = " + loc.getLatitude() + "Longitud = " + loc.getLongitude();
                Toast.makeText(getApplicationContext(), coordenadas, Toast.LENGTH_LONG).show();
            }
    
            public void onProviderDisabled(String provider) {
                Toast.makeText(getApplicationContext(), "Gps Desactivado", Toast.LENGTH_SHORT).show();
            }
    
            public void onProviderEnabled(String provider) {
                Toast.makeText(getApplicationContext(), "Gps Activo", Toast.LENGTH_SHORT).show();
            }
    
            public void onStatusChanged(String provider, int status, Bundle extras) {
            }
        }
    }
    

    我想知道为什么失败,我确信这是创建活动的问题。我一直在看一些有效的例子,但唯一的区别是与活动的参数通信

    1 回复  |  直到 7 年前
        1
  •  0
  •   David Wasser    7 年前

    GpsLocation Activity . 您可以这样做:

            //Here I create GpsLocation
            Intent intent = new Intent(v.getContext(), GpsLocation.class);
            toast.show();
    

    但这并没有开始 GpsLocation startActivity(intent) 在创建 Intent .