2016-09-14 7 views
0

私はそれに組み込まれたbixolonプリンターを備えた装置を持っています。私は、プリンタで印刷するためのアプリケーションを作成したいと思います。私のOnCreateの方法は、以下のようになります。ハンドラーが早くに火災する

protected override void OnCreate(Bundle bundle){ 
base.OnCreate(bundle); 
SetContentView(Resource.Layout.Main); 

printer = new BixolonPrinter(this, new MyHandler(), Looper.MainLooper); 
printer.FindUsbPrinters();  

//button connect 
Button button = FindViewById<Button>(Resource.Id.buttonConnect); 
button.Click += delegate {  
    printer.ConnectUsb();//in the brackets I would need the value of the Handler back once it is available 
}; } 

私のハンドラは以下の通りです:

private class MyHandler : Handler 
    { 
     public override void HandleMessage(Message msg) 
     {    
      switch (msg.What) 
      { 
       case BixolonPrinter.MessageUsbDeviceSet: 
        Console.WriteLine("U S B  device::: " + msg.Obj); 
        //can not return the msg.Obj back to the button event 
        break; 
      }   
     } 
    } 

問題はBixolonPrinterのインスタンスが作成されると、それはすぐにハンドラを起動します。ハンドラの結果をボタンイベントに戻す方法はありません。この問題をもっと複雑にするために、BixolonPrinterはJavaの.jarファイルです。どうすれば結果をイベントボタンに戻すことができますか?

答えて

0

MainLooperを使用すると、すべてがメインスレッドで実行されます。代わりにHandlerThreadを作成して対話を行います。実行を延期するには、Handler.postDelayed()メソッドを使用するか、RxJavaライブラリを使用してください。