在搜索界面的编辑框搜索时,界面一直停在onLoading,一直在转圈圈。
但在监听事件外面测试搜索方法时是没有问题的。所以是哪里出了问题呢?有没有小伙伴帮忙看看
doSearch()
@Override
public void doSearch(String keyword) {
LogUtils.d(this,"keyword==>"+keyword);
if (mCurrentKeyWord==null||!mCurrentKeyWord.endsWith(keyword)) {
this.saveHistory(keyword);
this.mCurrentKeyWord=keyword;
}
if (mSearchViewCallback != null) {
mSearchViewCallback.onLoading();
}
Call<SearchResult> task = mApi.doSearch(mCurrentPage, keyword);
task.enqueue(new Callback<SearchResult>() {
@Override
public void onResponse(Call<SearchResult> call, Response<SearchResult> response) {
int code = response.code();
LogUtils.d(SearchPresenterIml.this,"doSearch code--"+code);
if (code== HttpURLConnection.HTTP_OK) {
handleSearchResult(response.body());
}else{
onError();
}
}
@Override
public void onFailure(Call<SearchResult> call, Throwable t) {
t.printStackTrace();
onError();
}
});
}
搜索监听事件
@Override
protected void initListener() {
mSearchInputBox.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
LogUtils.d(this,"actionId-->"+actionId);
if (actionId== EditorInfo.IME_ACTION_SEARCH && mSearchPresenter != null) {
String keyword = v.getText().toString().trim();
LogUtils.d(this,"keyword-->"+keyword);
//trim()是去掉两边空格的意思
if (TextUtils.isEmpty(keyword)) {
return false;
}
mSearchPresenter.doSearch(keyword);
}
return false;
}
});
EditText控件
<EditText
android:id="@+id/search_input_box"
android:textSize="14sp"
android:maxLines="1"
android:focusable="true"
android:imeOptions="actionSearch"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_centerVertical="true"
android:hint="搜你想搜的宝贝"
android:singleLine="true"
android:background="@drawable/shape_edit_box_bg"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="@id/search_btn"
/>

handleSearchResult-->修改UI
看模拟器我还以为是苹果的 看了代码是安卓的