我正在使用键盘应用程序,我正在显示建议,当用户在此方法中键入内容时,我启动一个新的HandlerThread
,当该线程完成其作业后,我将发布到主线程更新ui但在结构上我我遇到了很多崩溃,但我找不到原因,我无法在我的设备上重新生成这是我发布的方法
这是我的HanlderThread
每当我想显示更新的建议时
private void showSuggestions(final String word) {
mSuggestionHandler.removeCallbacksAndMessages(null);
mSuggestionHandler.post(new Runnable() {
@Override
public void run() {
if (!word.contains("'") && !word.isEmpty()) {
getSuggestions(word);
} else mHandler.post(new Runnable() {
@Override
public void run() {
setNextSuggestions();
}
});
}
});
这是在非ui线程上运行的getSuggestions方法
private void getSuggestions(String word) {
Log.e("get:userDictSuggestions", word);
List<String> dictSuggetions = (List) this.mDictionary.complete(word);
if (dictSuggetions.size() > 18)
dictSuggetions = dictSuggetions.subList(0, 17);
userDictSuggestions.clear();
userDictSuggestions.addAll(dictSuggetions);
if (userDictSuggestions.size() > 0) {
if (this.mOldSuggestions.size() > 0) {
this.mOldSuggestions.clear();
}
this.mOldSuggestions.addAll(userDictSuggestions);
}
if (userDictSuggestions.size() < 18) {
userDictSuggestions.addAll(this.mOldSuggestions);
}
mSuggestions = userDictSuggestions;
mHandler.post(new Runnable() {
@Override
public void run() {
setSuggestions(mSuggestions, null, false, false);
}
});
}
这是我的节目建议方法
private void setSuggestions(List<String> suggestions, boolean completions, boolean typedWordValid, boolean haveMinimalSuggestion) {
if (this.mIsShowingHint) {
setCandidatesView(this.mCandidateViewContainer);
this.mIsShowingHint = false;
}
this.candidatesAdapter = new CandidatesAdapter(suggestions);
this.suggestionsRecyclerView.setAdapter(this.candidatesAdapter);
this.candidatesAdapter.notifyDataSetChanged();
}
我正在接受这些崩溃
Fatal Exception: java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 3(offset:3).state:34 android.support.v7.widget.RecyclerView{447a1378 VFED.... .F....ID 6,0-708,53 #7f0a0138 app:id/suggestions_recycler_view}, adapter:.keyboard.inputmethod.LatinIME$a@44ec2ef0, layout:android.support.v7.widget.LinearLayoutManager@447cb440, context:keyboard.inputmethod.LatinIME@41c40578
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5817)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5752)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5748)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2232)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1559)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1519)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:614)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3812)
at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3225)
at android.view.View.measure(View.java:16508)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5162)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1052)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:590)
at android.view.View.measure(View.java:16508)
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1034)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:590)
at android.view.View.measure(View.java:16508)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5162)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16508)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5162)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16508)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5162)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16508)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5162)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16508)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5162)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16508)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5162)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16508)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5162)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2317)
at android.view.View.measure(View.java:16508)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1921)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1113)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1295)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5691)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5281)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:932)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:748)
at dalvik.system.NativeStart.main(NativeStart.java)