我正在努力獲得一個處理程序顯示一個吐司messgae,其中還包含從msg.obj提取的變量。它不給我任何錯誤,但吐司消息不顯示。這裏是代碼問題與處理程序內的Toast
Handler nok=new Handler() {
public void handleMessage(Message msg)
{
Location locator=(Location)msg.obj;
float lat=(float)(locator.getLatitude());
Toast.makeText(m,"the latitude is+lat,Toast.LENGTH_LONG).show();
}
我也嘗試添加
runOnUiThread(new Runnable()
{
public void run(){
Toast.makeText(m,"the latitude is" +lat,Toast.LENGTH_LONG).show();
}
但在這種情況下,變量LAT沒有處理程序外的認可,任何想法?
整個類是
public class MainActivity extends Activity {
public static final String content="Asega kvo stava";
public static final Integer kom=2;
Context m;
Looper lupy;
Handler ok;
Handler nok=new Handler() {
public void handleMessage(Message msg)
{
System.out.println("Check");
Location locator=(Location)msg.obj;
float lat=(float)(locator.getLatitude());
Toast.makeText(MainActivity.this,"the latitude is"+" "+lat,Toast.LENGTH_LONG).show();
}
};
和類張貼訊息話題:
public class locac implements LocationListener {
public Context Ctx;
Handler nok;
public static String okai="Ctx.LOCATION_SERVICE";
public static String moi="manag.GPS_PROVIDER";
Location loc;
public locac (Context context,Handler handler)
{
this.nok=handler;
this.Ctx=context;
}
public void getLoc (Location Loc)
{
if(loc!=null)
{
LocationManager manag;
manag=(LocationManager)Ctx.getSystemService(okai);
Message kol=new Message();
kol.obj=loc;
nok.sendMessage(kol);
}
}
什麼是變量'm'? – Ogen
我沒有看到任何東西被稱爲,它只是所有的方法。 – Ogen