我正在使用列表视图和搜索栏。当我单击任何搜索到的项目以发送另一个活动时,它将发送0。当我搜索并单击时,这是我的问题 搜索时我该如何获取真实位置(以获得默认位置)?
wordSearch = findViewById(R.id.search_text);
listView = findViewById(R.id.list);
items = wordsArray ;
arrayList = new ArrayList<>(Arrays.asList(items));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override`enter code here`
public void onItemClick(AdapterView<?> parent, View view, int
position, long id) {
Intent intent = new Intent(search.this, lektion1.class);
String sendData = wordsArray[position] ;
intent.putExtra("sendData",sendData);
long selectedId = listView.getItemIdAtPosition(position);
intent.putExtra("id",String.valueOf(selectedId));
startActivity(intent);
finish();
}
});
adapter = new ArrayAdapter<>
(this,R.layout.list_item,R.id.tv,arrayList);
listView.setTextFilterEnabled(true);
listView.setAdapter(adapter);
wordSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int
count) {
search.this.adapter.getFilter().filter(s);
adapter.notifyDataSetChanged();
}