渲染器 - onElementChanged多次调用

时间:2016-06-01 14:03:17

标签: android xamarin xamarin.android

我的应用程序中有一个简单的页面,其中有一个ListView,ViewCells中的一些条目和底部的一个按钮。

可以在https://www.dropbox.com/sh/b2jzl7v9fnxqrng/AAANh2naAg2t9Kr6gN1lUsrGa?dl=0

找到它的源代码

问题是,当一个项目有一个数量时,该按钮覆盖了以下条目(当显示键盘时),因此用户无法看到,他/她正在写什么(我只想显示按钮,如果有任何条目有金额)。
因为它现在是正确的,但在某种程度上,事件发生了很多次,并且它以死锁结束。

有人知道如何解决它吗?

目前,我无法更新到Xamarin Forms 2,因为SignaturePad依赖于Xamarin Forms 1.5

正如我所看到的,问题在于,每个元素不止一次地调用它。

protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
   base.OnElementChanged(e);

   EKEntry base_entry = (EKEntry)this.Element;

   if (Control != null && base_entry != null)
   {
      if (base_entry.ForceBackgroundColor.HasValue)
      {
         if (base_entry.ForceBackgroundColor.Value == Color.White)
         Control.SetBackgroundColor(Android.Graphics.Color.White);
      }

      if (base_entry.DisableScrolling)
      {
         var activity = Forms.Context as Activity;
         if (activity != null)
         {
            activity.Window.SetSoftInputMode(SoftInput.AdjustNothing);
         }
      }
   }
}

我尝试在Focuschange中设置softinputmode但没有成功。

控制台中的输出是

06-02 07:54:55.296 W/IInputConnectionWrapper(26975): getExtractedText on inactive InputConnection
06-02 07:54:55.301 W/View    (26975): requestLayout() improperly called by com.android.internal.policy.impl.PhoneWindow$DecorView{1e1539da V.E..... R....... 0,0-1080,1776} during second layout pass: posting in next frame
06-02 07:54:55.302 W/View    (26975): requestLayout() improperly called by md5282f1122c1313907b9bf274dd2c2f344.EntryEditText{b74e164 VFED..CL .F...... 0,0-180,150} during second layout pass: posting in next frame
06-02 07:54:55.302 W/IInputConnectionWrapper(26975): getTextBeforeCursor on inactive InputConnection
06-02 07:54:55.731 W/View    (26975): requestLayout() improperly called by md5282f1122c1313907b9bf274dd2c2f344.EntryEditText{19e1247d VFED..CL ......ID 0,0-180,150} during layout: running second layout pass
06-02 07:54:55.731 W/View    (26975): requestLayout() improperly called by md5282f1122c1313907b9bf274dd2c2f344.EntryEditText{b74e164 VFED..CL .F....ID 0,0-180,150} during layout: running second layout pass
06-02 07:54:56.054 I/Choreographer(26975): Skipped 43 frames!  The application may be doing too much work on its main thread.
06-02 07:54:56.064 W/IInputConnectionWrapper(26975): finishComposingText on inactive InputConnection
06-02 07:54:56.064 W/IInputConnectionWrapper(26975): finishComposingText on inactive InputConnection
06-02 07:54:56.065 W/IInputConnectionWrapper(26975): getExtractedText on inactive InputConnection
06-02 07:54:56.069 W/View    (26975): requestLayout() improperly called by com.android.internal.policy.impl.PhoneWindow$DecorView{1e1539da V.E..... R....... 0,0-1080,1776} during second layout pass: posting in next frame
06-02 07:54:56.069 W/View    (26975): requestLayout() improperly called by md5282f1122c1313907b9bf274dd2c2f344.EntryEditText{b74e164 VFED..CL .F...... 0,0-180,150} during second layout pass: posting in next frame
06-02 07:54:56.069 W/IInputConnectionWrapper(26975): getTextBeforeCursor on inactive InputConnection
06-02 07:54:56.406 W/View    (26975): requestLayout() improperly called by md5282f1122c1313907b9bf274dd2c2f344.EntryEditText{19e1247d VFED..CL ......ID 0,0-180,150} during layout: running second layout pass
06-02 07:54:56.406 W/View    (26975): requestLayout() improperly called by md5282f1122c1313907b9bf274dd2c2f344.EntryEditText{b74e164 VFED..CL .F....ID 0,0-180,150} during layout: running second layout pass
06-02 07:54:57.275 I/art     (26975): Explicit concurrent mark sweep GC freed 86858(2MB) AllocSpace objects, 0(0B) LOS objects, 9% free, 148MB/164MB, paused 1.575ms total 41.493ms
06-02 07:54:57.296 D/Mono    (26975): GC_OLD_BRIDGE num-objects 3788 num_hash_entries 100267 sccs size 47151 init 0.00ms df1 285.92ms sort 59.40ms dfs2 126.79ms setup-cb 10.71ms free-data 237.97ms links 176105/176105/1213352/28 dfs passes 280160/223256
06-02 07:54:57.296 D/Mono    (26975): GC_MINOR: (Nursery full) pause 334.55ms, total 334.65ms, bridge 0.00ms promoted 8176K major 8176K los 2320K
06-02 07:54:57.599 I/Choreographer(26975): Skipped 89 frames!  The application may be doing too much work on its main thread.
06-02 07:54:57.605 W/IInputConnectionWrapper(26975): finishComposingText on inactive InputConnection
06-02 07:54:57.605 W/IInputConnectionWrapper(26975): getExtractedText on inactive InputConnection
06-02 07:54:57.607 W/View    (26975): requestLayout() improperly called by com.android.internal.policy.impl.PhoneWindow$DecorView{1e1539da V.E..... R....... 0,0-1080,1776} during second layout pass: posting in next frame
06-02 07:54:57.607 W/View    (26975): requestLayout() improperly called by md5282f1122c1313907b9bf274dd2c2f344.EntryEditText{b74e164 VFED..CL .F...... 0,0-180,150} during second layout pass: posting in next frame
06-02 07:54:57.607 W/IInputConnectionWrapper(26975): getTextBeforeCursor on inactive InputConnection
06-02 07:54:57.926 W/View    (26975): requestLayout() improperly called by md5282f1122c1313907b9bf274dd2c2f344.EntryEditText{19e1247d VFED..CL ......ID 0,0-180,150} during layout: running second layout pass
06-02 07:54:57.926 W/View    (26975): requestLayout() improperly called by md5282f1122c1313907b9bf274dd2c2f344.EntryEditText{b74e164 VFED..CL .F....ID 0,0-180,150} during layout: running second layout pass

当我只输入金额时的截图 A screenshot of how it looks like, when I have only entered an amount

上面的输出发生时(键盘没有显示)的截图 A screenshot of how it looks like when the output above occurs (the keyboard does not show up)

当一个条目聚焦时,我滚动到该项目,使用_lstMaterials.ScrollTo(item, ScrollToPosition.Start, false);将其显示为ListView中的第一项,然后检查文本是空还是空,因为它必须刷新光标(通过将文本设置为“”,因为光标有时不会出现。)

更新
我发现,可能会因为多次调用FocusedUnfocused事件而发生这种情况。但是我看不出,为什么会这样,以及如何防止它。

0 个答案:

没有答案