我在操作栏中集成了搜索栏。我想要显示来自两个不同api调用的数据的建议列表,所以我在onChiteTextChange()中调用了两个api,但问题是第一个数据是从第一个api调用显示的,然后是数据被第二个api调用的数据替换。如何在searchview的建议列表中显示来自两个不同的api调用的数据?
@Override
public boolean onQueryTextChange(String s) {
if(s.length()>=3) {
String mStart = "";
int mCount = 10;
String[] columnNames = {"_id", "name", "userImage", "location"};
final String[] temp = new String[5];
final MatrixCursor cursor = new MatrixCursor(columnNames);
SearchAPI.getSearchFeed(getApplicationContext(), s, mStart, mCount, mSettingsManager.getInstance().getAccessToken(), new APIResponseListener() {
@Override
public void onResponse(Object response) {
searchResponses= (List<Video>) response;
for (Video searchResponse :searchResponses) {
temp[0] = Long.toString(id++);
temp[1] = searchResponse.getCaption();
temp[3] = searchResponse.getLocation();
cursor.addRow(temp);
}
mSearchView.setSuggestionsAdapter(new SearchListAdapter(HomeActivity.this, cursor));
}
@Override
public void onError(VolleyError error) {
if (error instanceof NoConnectionError) {
}
}
});
SearchAPI.getSearchUser(getApplicationContext(), s,mSettingsManager.getInstance().getAccessToken(), new APIResponseListener() {
@Override
public void onResponse(Object response)
{
userResponses = (List<User>) response;
for (User searchResponse :userResponses) {
temp[0] = Long.toString(id++);
temp[1] = searchResponse.getUserName();
temp[3] = searchResponse.getEmail();
cursor.addRow(temp);
}
mSearchView.setSuggestionsAdapter(new SearchListAdapter(HomeActivity.this, cursor));
}
@Override
public void onError(VolleyError error)
{
if (error instanceof NoConnectionError) {
}
}
});
}
return true;
}
答案 0 :(得分:1)
尝试,