[英]Roasting of toasts created in an activity that is a call from another class does not work
从一个类中,我正在创建另一个类中定义的活动。 此类具有void方法,但它们不会返回任何内容,但会打印吐司。 具体来说,它们是gps值,其想法是创建意图并暂时打印值,但它不起作用
我从中创建“ 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();
}
});
我用无效方法定义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) {
}
}
}
我想知道为什么失败,我确定这是创建活动的问题。 我一直在看一些可行的示例,但唯一的区别是在此活动中通过参数进行通信
您永远不会启动GpsLocation Activity
。 你做这个:
//Here I create GpsLocation
Intent intent = new Intent(v.getContext(), GpsLocation.class);
toast.show();
但这不会启动GpsLocation
。 创建Intent
后,您需要调用startActivity(intent)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.