首先,我想向您保证,我已经阅读了大量关于SO的类似帖子,并且尚未找到我的问题的答案。
所以,问题(或者我应该说问题): 我有一个列表视图,其中包含非常棘手的项目,其中包含文本视图,按钮和编辑文本。所有这些项都是动态生成的。是的,我有最糟糕和最烦人的(有这样的话吗?)你可以在Android开发中想象的东西。因此,为了控制所有这些混乱,我有地狱机器,它包含关于焦点,编辑文本中的光标位置和其他很酷的东西的所有信息。它真的是一大堆代码,我相信没有人想看到它,也是绝密的(开玩笑)。
所以,问题。当我点击编辑文本以在其中输入smth时,我的Adapter的方法getView()开始无休止地被调用大约200次(即在循环中)。虽然,它不会影响文本输入或其他东西,但这完全不正常。在调试时,我看到onMeasure()方法最终调用了我的getView(),然后(出于某种原因)进入循环。
所以我的问题是:onMeasure如何进入循环,这怎么可能?我只是点击编辑文本而没有别的,我没有输入任何数据,我不滚动我的列表,我甚至没有触摸我的手机,它不会自动移动。
我觉得自己不好不给你我的全部代码,所以至少我会给你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]
答案 0 :(得分:0)
这是因为ListView的layout_height值= wrap_content。将此设置为fill_parent修复了问题