Xamarin Android popupwindow-充气时崩溃
我正在尝试创建一个弹出窗口,显示一个时钟,实际上我想要的是一个倒计时计时器,但一次只能显示一个!,问题是,当我调用该方法显示包含时钟的弹出窗口时,应用程序崩溃 正在从活动而不是片段调用该方法 代码如下:Xamarin Android popupwindow-充气时崩溃,xamarin,xamarin.android,clock,popupwindow,countdowntimer,Xamarin,Xamarin.android,Clock,Popupwindow,Countdowntimer,我正在尝试创建一个弹出窗口,显示一个时钟,实际上我想要的是一个倒计时计时器,但一次只能显示一个!,问题是,当我调用该方法显示包含时钟的弹出窗口时,应用程序崩溃 正在从活动而不是片段调用该方法 代码如下: public void clockPopup() { LayoutInflater inflater =(LayoutInflater)this.GetSystemService(Context.LayoutInflaterService); View myPopup = i
public void clockPopup()
{
LayoutInflater inflater =(LayoutInflater)this.GetSystemService(Context.LayoutInflaterService);
View myPopup = inflater.Inflate (Resource.Layout.PopUpClockTimer, null);
RunOnUiThread (() => {
PopupWindow popup = new PopupWindow (myPopup);
});
}
堆栈跟踪如下所示:
[mono] Unhandled Exception:
[mono] Android.Views.InflateException: Exception of type 'Android.Views.InflateException' was thrown.
[mono] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0
[mono] at Android.Runtime.JNIEnv.CallObjectMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00000] in <filename unknown>:0
[mono] at Android.Views.LayoutInflater.Inflate (Int32 resource, Android.Views.ViewGroup root) [0x00000] in <filename unknown>:0
[mono] at FrogPoint.Droid.MainActivity.clockPopup () [0x00020] in /Users/jakememery/Desktop/working Frogpoint/FrogPoint1.2_database/FindTheMonkey.Droid/MainActivity.cs:1548
[mono] at FrogPoint.Droid.MainActivity+<getBeaconData>c__async3.MoveNext () [0x00258] in /Users/jakememery/Desktop/working Frogpoint/FrogPoint1.2_database/FindTheMonkey.Droid/MainActivity.cs:1215
[mono] --- End of stack trace from previous location where exception was thrown ---
[mono] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0
[mono] at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <filename unknown>:0
[mono] at FrogPoint.Droid.MainActivity+<RangingBeaconsInRegion>c__async0.MoveNext () [0x0035d] in /Users/jakememery/Desktop/working Frogpoint/FrogPoint1.2_database/FindTheMonkey.Droid/MainActivity.cs:675
[mono] --- End of managed exception stack trace ---
[mono] android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.AnalogClock
[mono] at android.view.LayoutInflater.createView(LayoutInflater.java:620)
[mono] at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
[mono] at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
[mono] at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
[mono] at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
[mono] at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
[mono] at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
[mono] at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
[mono] at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
[mono] at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
[mono] at dalvik.system.NativeStart.run(Native Method)
[mono] Caused by: java.lang.reflect.InvocationTargetException
[mono] at java.lang.reflect.Constructor.constructNative(Native Method)
[mono] at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
[mono] at android.view.LayoutInflater.createView(LayoutInflater.java:594)
[mono] ... 10 more
[mono] Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
[mono] at android.os.Handler.<init>(Handler.java:200)
[mono] at android.os.Handler.<init>(Handler.java:114)
[mono] at android.widget.AnalogClock.<init>(AnalogClock.java:57)
[mono] at android.widget.AnalogClock.<init>(AnalogClock.java:67)
下面是我试图膨胀的XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/customborder"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:orientation="vertical">
<TextView
android:id="@+id/textout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Time sensitive offer" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/logo76" />
<AnalogClock
android:id="@+id/tabAnalogClock"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<DigitalClock
android:id="@+id/tabDigitalClock"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/dismiss"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Dismiss" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
有人能看出我哪里出了问题吗 我似乎只需要像这样调用该方法:
RunOnUiThread (() => {
clockPopup();
});
它现在没有崩溃。但不幸的是,它也没有显示弹出窗口。但这是另一篇文章。你错过了:
popup.ShowAtLocation(...);
或
以实际显示弹出窗口。您可以发布您试图膨胀的XML文件吗?那将有助于分配!嗨,克里斯,XML补充道,但碰巧我已经解决了这个问题。我需要通过runOnUiThread调用该方法。现在没有撞车。但是,现在发生了什么。。。。什么都不是。弹出窗口就是不显示。如果我只是使用SetContentView Resource.Layout.PopUpClockTimer;它显示得很好,但显然我不会以弹出窗口的形式打开它。这方面的任何帮助都会很好。否则我将打开一个新线程。非常感谢。
popup.ShowAsDropDown(...);