如果没有采取任何行动,请测量无限循环

时间:2022-12-01 23:11:56

First, I'd like to assure you that I've read tons of similar posts on SO and answer to MY question is yet to be found.

首先,我想向您保证,我已经阅读了大量关于SO的类似帖子,并且尚未找到我的问题。

So, the question (or I should say the problem): I have a list view with pretty tricky items with text views, buttons, edit texts inside them. All these items are generated dynamically. Yes, I have the worst and buggiest (is there such word?) thing you can imagine in Android developement. So, to control all this mess I have the Hell Machine, that holds all info about focuses, cursor positions in edit texts and other cool stuff. It is really a very big bunch of code and I'm sure no one of you wants to see it, also it's top-secret (joking).

所以,问题(或者我应该说问题):我有一个列表视图,其中包含非常棘手的项目,其中包含文本视图,按钮,编辑文本。所有这些项都是动态生成的。是的,我在Android开发中可以想象出最糟糕,最烦人的(有这样的话吗?)。因此,为了控制所有这些混乱,我有地狱机器,它包含有关焦点,编辑文本中的光标位置和其他很酷的东西的所有信息。它真的是一大堆代码,我相信没有人想看到它,也是绝密的(开玩笑)。

So, the PROBLEM. When I tap on edit text to type smth in it, my Adapter's method getView() begins getting called about 200 hundred of times endlessly (i.e. in a loop). Though, it does not affect text input or something else, but this is completely not normal. While debugging, I saw that onMeasure() method eventually calles my getView(), and then (for some reason) goes into a loop.

所以,问题。当我点击编辑文本以在其中键入smth时,我的Adapter的方法getView()开始无休止地被调用大约200次(即在循环中)。虽然,它不会影响文本输入或其他东西,但这完全不正常。在调试时,我看到onMeasure()方法最终调用了我的getView(),然后(由于某种原因)进入循环。

So my question is: how is this even possible that onMeasure goes into a loop? I just tapped on edit text and nothing else, I do not input any data in it, I don't scroll my list, I don't even touch my phone and it does not move by itself.

所以我的问题是:如果onMeasure进入循环,这怎么可能呢?我只是点击编辑文本而没有别的,我没有输入任何数据,我不滚动我的列表,我甚至没有触摸我的手机,它不会自动移动。

I feel myself bad for not giving you the whole code I have, so at least I'll give you the stack trace of the onMeasure() method.

我觉得自己不好不给你我的全部代码,所以至少我会给你onMeasure()方法的堆栈跟踪。

StaticLayout(Layout).getWidth() line: 537   
TextView.onMeasure(int, int) line: 6188 
TextView(View).measure(int, int) line: 15172    
LinearLayout(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 4816    
LinearLayout.measureChildBeforeLayout(View, int, int, int, int, int) line: 1390 
LinearLayout.measureHorizontal(int, int) line: 1038 
LinearLayout.onMeasure(int, int) line: 576  
LinearLayout(View).measure(int, int) line: 15172    
HorizontalScrollView.measureChildWithMargins(View, int, int, int, int) line: 1216   
HorizontalScrollView(FrameLayout).onMeasure(int, int) line: 310 
HorizontalScrollView.onMeasure(int, int) line: 299  
HorizontalScrollView(View).measure(int, int) line: 15172    
RelativeLayout.measureChildHorizontal(View, RelativeLayout$LayoutParams, int, int) line: 617    
RelativeLayout.onMeasure(int, int) line: 399    
RelativeLayout(View).measure(int, int) line: 15172  
FrameLayout(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 4816 
FrameLayout.onMeasure(int, int) line: 310   
FrameLayout(View).measure(int, int) line: 15172 
LinearLayout.measureVertical(int, int) line: 833    
LinearLayout.onMeasure(int, int) line: 574  
LinearLayout(View).measure(int, int) line: 15172    
PhoneWindow$DecorView(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 4816   
PhoneWindow$DecorView(FrameLayout).onMeasure(int, int) line: 310    
PhoneWindow$DecorView.onMeasure(int, int) line: 2220    
PhoneWindow$DecorView(View).measure(int, int) line: 15172   
ViewRootImpl.performMeasure(int, int) line: 1850    
ViewRootImpl.measureHierarchy(View, WindowManager$LayoutParams, Resources, int, int) line: 1102 
ViewRootImpl.performTraversals() line: 1275 
ViewRootImpl.doTraversal() line: 1000   
ViewRootImpl$TraversalRunnable.run() line: 4214 
Choreographer$CallbackRecord.run(long) line: 725    
Choreographer.doCallbacks(int, long) line: 555  
Choreographer.doFrame(long, int) line: 525  
Choreographer$FrameDisplayEventReceiver.run() line: 711 
Handler.handleCallback(Message) line: 615   
Choreographer$FrameHandler(Handler).dispatchMessage(Message) line: 92   
Looper.loop() line: 137 
ActivityThread.main(String[]) line: 4787    
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
Method.invoke(Object, Object...) line: 511  
ZygoteInit$MethodAndArgsCaller.run() line: 789  
ZygoteInit.main(String[]) line: 556 
NativeStart.main(String[]) line: not available [native method]  

1 个解决方案

#1


0  

It was because of ListView's layout_height value = wrap_content. Setting this to fill_parent fixed the issue

这是因为ListView的layout_height值= wrap_content。将此设置为fill_parent可以解决问题

#1


0  

It was because of ListView's layout_height value = wrap_content. Setting this to fill_parent fixed the issue

这是因为ListView的layout_height值= wrap_content。将此设置为fill_parent可以解决问题