Android studio 在使用SearchView进行筛选后,如何通过单击片段内ListView中的元素转到正确的片段详细信息?

Android studio 在使用SearchView进行筛选后,如何通过单击片段内ListView中的元素转到正确的片段详细信息?,android-studio,android-fragments,android-listview,searchview,android-filter,Android Studio,Android Fragments,Android Listview,Searchview,Android Filter,我正在开发一个应用程序,其中我有一个神奇宝贝列表,列表视图在一个片段中,当我点击一个神奇宝贝时,该应用程序会转到另一个包含神奇宝贝细节片段的活动,到目前为止,一切都很好。 我有一个包含搜索视图的菜单,搜索效果很好,但问题是当我点击一个神奇宝贝时,该应用程序会在列表视图中的该位置显示神奇宝贝的详细信息,而不是显示我点击的右侧神奇宝贝的详细信息 (我还不能放图片) 在进行搜索之前,我有以下内容: 我的列表: Bulbasaur(ListView中的ID=0) Ivysaur(ListView中的ID

我正在开发一个应用程序,其中我有一个神奇宝贝列表,列表视图在一个片段中,当我点击一个神奇宝贝时,该应用程序会转到另一个包含神奇宝贝细节片段的活动,到目前为止,一切都很好。 我有一个包含搜索视图的菜单,搜索效果很好,但问题是当我点击一个神奇宝贝时,该应用程序会在列表视图中的该位置显示神奇宝贝的详细信息,而不是显示我点击的右侧神奇宝贝的详细信息

(我还不能放图片)

在进行搜索之前,我有以下内容:

我的列表:

Bulbasaur(ListView中的ID=0)

Ivysaur(ListView中的ID=1)

Venusaur(ListView中的ID=2)

Charmander(ListView中的ID=3)

Charmeleon(ListView中的ID=4)

等等

然后我点击Ivysaur,获得Ivysaur的详细信息

当我进行搜索时,我得到以下信息:

我搜索包含“b”的神奇宝贝,我的列表变成这样:

Bulbasaur(ListView中的ID=0)

BLOSOISE(ListView中的ID=1)

Butterfree(ListView中的ID=2)

Beedrill(ListView中的ID=3)

等等

我点击Blanoise(ID=1)并获得Ivysaur的详细信息 我想这是因为在最初的列表中,Ivysaur的ID=1

BindFragmentsPokedexActivity.java

公共类BindFragmentsPokedexActivity扩展了AppCompativeActivity
实现PokedexFragment.OnFragmentInteractionListener
,PokedexSettingsDialogFragment.OnPokemonTypeFilterListener{
@BindView(R.id.pokedex)
工具栏;
私有列表视图pkmListView;
私人名单;
专用PokedexAdapter适配器;
公共静态int filterFlag;
@凌驾
受保护的void onCreate(Bundle savedInstanceState){/*m./*m.onCreate*/
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u bind\u fragments\u pokedex);
把(这个)绑起来;
工具栏();
}/*m.onCreate*/
@凌驾
公共void onPokemonClick(pokemonpkm){/*m.onPokemonClick*/
setPokedexDataExtras(pkm);
}/*m.onPokemonClick*/
私有void setPokedexDataExtras(Pokemon pkm){/*m.setPokedexDataExtras*/
Intent Intent=新的Intent(这个,PokemonDetailsActivity.class);
intent.putExtra(“NormalPkmPic”,pkm.getPokemonPicResId());
intent.putExtra(“ShinyPkmPic”,pkm.getPokemonShinyPicResId());
intent.putExtra(“PkmName”,pkm.getpokemoname());
intent.putExtra(“PkmDexNum”,pkm.getPokemonDexNum());
intent.putExtra(“PkmType1”,pkm.getPokemonType1());
intent.putExtra(“PkmType2”,pkm.getPokemonType2());
intent.putExtra(“DexNum”,pkm.getDexNum());
intent.putExtra(“isMega”,pkm.isMega());
intent.putExtra(“isAlolan”,pkm.isAlolan());
intent.putExtra(“PkmType1Search”,pkm.getPokemonType1Search());
intent.putExtra(“PkmType2Search”,pkm.getPokemonType2Search());
星触觉(意向);
}/*m.SetpokedExdata额外*/
@凌驾
公共布尔onCreateOptions菜单(菜单菜单){/*m.onCreateOptions菜单*/
super.onCreateOptions菜单(菜单);
getMenuInflater().充气(R.menu.pokedex_菜单,菜单);
pkmListView=findviewbyd(R.id.listViewPokedex);
pkmList=pokemondasource.getPokemonList();
adapter=new PokedexAdapter(BindFragmentsPokedexActivity.this,R.layout.list\u view\u pokemon
,pkmList);
pkmListView.setAdapter(适配器);
filterFlag=0;
MenuItem searchItem=menu.findItem(R.id.pokedex_search);
SearchView SearchView=(SearchView)searchItem.getActionView();
setQueryHint(getResources().getString(R.string.search_菜单));
searchView.setOnQueryTextListener(新的searchView.OnQueryTextListener(){
@凌驾
公共布尔值onQueryTextSubmit(字符串查询){
返回false;
}
@凌驾
公共布尔onQueryTextChange(字符串newText){
adapter.getFilter().filter(newText);
返回true;
}
});
返回true;
}/*m.onCreateOptions菜单*/
@凌驾
公共布尔值onOptionsItemSelected(MenuItem项){/*m.onOptionsItemSelected*/
开关(item.getItemId()){/*1*/
案例R.id.pokedex_类型:{
打破
}/*案例R.id.pokedex_类型*/
案例R.id.pokedex_设置:{
新建PokedexSettingsDialogFragment().show(getSupportFragmentManager())
,“PokedexSettingsDialogFragment”);
打破
}/*案例R.id.pokedex_设置*/
} /*1.*/
返回super.onOptionsItemSelected(项目);
}/*m.onOptionsItemSelected*/
@凌驾
public void onTypeFilter(TextView pkmType){
pkmType.addTextChangedListener(新的TextWatcher(){
@凌驾
public void beforeTextChanged(字符序列s、int start、int count、int after){/*m.beforeTextChanged*/
}/*m.beforetextchange*/
@凌驾
public void onTextChanged(字符序列s,int start,int before,int count){/*m.onTextChanged*/
filterFlag=1;
adapter.getFilter().filter;
}/*m.onTextChanged*/
@凌驾
public void posterextchanged(可编辑的s){/*m.posterextchanged*/
}/*m*/
});
}/*m.onTypeFilter*/
}//BindFragmentsPokedexActivity
PokedexFragment.java

public类PokedexFragment扩展片段{
私人无障碍者;
@BindView(R.id.listViewPokedex)
列表视图pkmListView;
私人PokedexAdapter PokedexAdapter;