0
任何人都可以幫助我如何修復listview的searchview錯誤的結果。例如我有列表視圖(1,2,3,4,5)的數據當我從searchview搜索數據2時,我點擊它,總是顯示數據1,當我沒有從searchview搜索數據時,結果如果爲真,我點擊數據1只顯示1,圖2示出2搜索ListView與onClick視圖顯示錯誤的結果
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.listview);
final String[] values= new String[]{"button1","button2","buttton3"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.activity_list_item,android.R.id.text1,values);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view,
int position, long id) {
if(position==0){
Intent myintent = new Intent(view.getContext(),Main2Activity.class);
startActivityForResult(myintent,0);
}
if(position==1){
Intent myintent = new Intent(view.getContext(),Main3Activity.class);
startActivityForResult(myintent,1);
}
if(position==2){
Intent myintent = new Intent(view.getContext(),Main2Activity.class);
startActivityForResult(myintent,2);
}
}
});
謝謝!我會盡力實施它 – Sebastian