gpt4 book ai didi

java - 将数据传递给 OnItemClickListener?

转载 作者:行者123 更新时间:2023-12-01 07:40:24 29 4
gpt4 key购买 nike

DataAccess data = new DataAccess(db);
List<String> countries = data.getCountries();

setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, countries));

ListView lv = getListView();
lv.setTextFilterEnabled(true);

lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {

// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
}
});

如何从 onItemClick 方法内部传递和访问 data 变量?

最佳答案

make data final 并且您应该能够在 onItemClick 中使用 data

引用它

关于java - 将数据传递给 OnItemClickListener?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5710488/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com