list = new ArrayList<String>();
//videos list
list.add("Video1");
list.add("Video2");
list.add("Video3");
list.add("Video4");
list.add("Video5");
list.add("Video6");
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,list);
listView.setAdapter(adapter);
//opens activities
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
switch (Integer.parseInt((String) adapter.getItem(position))) {
case 0:
Intent newActivity = new Intent(list_videos.this,Video1.class);
startActivity(newActivity);
break;
}
}
});
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
return false;
}
@Override
public boolean onQueryTextChange(String s) {
adapter.getFilter().filter(s);
return false;
}
});
}
}
I have created a list-view and on top of that I added a search-bar.
When I use the search-bar, to filter the results... when I click on item 7, instead of opening the specific clicked activity i.e. 7, it always starts from the first one.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…