community keep position when update search

This commit is contained in:
kehaoyuan
2019-04-29 10:57:46 +08:00
parent 926abe248f
commit b2b390cf8b
2 changed files with 36 additions and 9 deletions

View File

@ -270,16 +270,29 @@ public class AskSearchActivity extends BaseActivity {
transaction.hide(fragment);
}
if (mSearchKey == null || mSearchKey.isEmpty()) {
HistoryFragment historyFragment = new HistoryFragment();
transaction.replace(R.id.layout_fragment_content, historyFragment);
String historyTag = HistoryFragment.class.getSimpleName();
Fragment fragment = getSupportFragmentManager().findFragmentByTag(historyTag);
if (fragment != null) {
transaction.show(fragment);
} else {
HistoryFragment historyFragment = new HistoryFragment();
transaction.add(R.id.layout_fragment_content, historyFragment, historyTag);
}
} else {
AskSearchFragment searchFragment = new AskSearchFragment();
Bundle args = new Bundle();
args.putString(EntranceUtils.KEY_SEARCHKEY, mSearchKey);
args.putString(EntranceUtils.KEY_COLUMN_ID, mColumnId);
args.putString(EntranceUtils.KEY_QUESTION_TAG, mQuestionTag);
searchFragment.setArguments(args);
transaction.replace(R.id.layout_fragment_content, searchFragment);
String searchTag = AskSearchFragment.class.getSimpleName();
Fragment fragment = getSupportFragmentManager().findFragmentByTag(searchTag);
if (fragment instanceof AskSearchFragment) {
((AskSearchFragment) fragment).updateSearch(mSearchKey);
transaction.show(fragment);
} else {
AskSearchFragment searchFragment = new AskSearchFragment();
Bundle args = new Bundle();
args.putString(EntranceUtils.KEY_SEARCHKEY, mSearchKey);
args.putString(EntranceUtils.KEY_COLUMN_ID, mColumnId);
args.putString(EntranceUtils.KEY_QUESTION_TAG, mQuestionTag);
searchFragment.setArguments(args);
transaction.add(R.id.layout_fragment_content, searchFragment, AskSearchFragment.class.getSimpleName());
}
}
transaction.commitAllowingStateLoss();
}

View File

@ -11,6 +11,7 @@ import com.gh.base.fragment.BaseFragment_TabLayout;
import com.gh.common.util.EntranceUtils;
import com.gh.gamecenter.R;
import com.gh.gamecenter.qa.search.artilce.ArticleFragment;
import com.gh.gamecenter.qa.search.base.BaseAskSearchFragment;
import com.gh.gamecenter.qa.search.hottest.HottestFragment;
import com.gh.gamecenter.qa.search.newest.NewestFragment;
import com.gh.gamecenter.qa.search.question.QuestionFragment;
@ -84,4 +85,17 @@ public class AskSearchFragment extends BaseFragment_TabLayout {
}
}
}
void updateSearch(String key) {
for (Fragment fragment : mFragmentsList) {
if (fragment instanceof BaseAskSearchFragment) {
((BaseAskSearchFragment) fragment).search(key);
Bundle arguments = fragment.getArguments();
if (arguments != null) {
arguments.putString(EntranceUtils.KEY_SEARCHKEY, key);
fragment.setArguments(arguments);
}
}
}
}
}