gpt4 book ai didi

java - 具有多个数组的自定义适配器 OnItemClick

转载 作者:行者123 更新时间:2023-12-01 13:10:21 26 4
gpt4 key购买 nike

public void populate(ArrayList<String> array, ArrayList<String> array2) {
ListView showList = (ListView) findViewById(R.id.listView1);
SchedAdapter shows = new SchedAdapter(getApplicationContext(),
R.layout.rowlayout, array, array2);
showList.setAdapter(shows);
showList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, final View view,
final int position, long id) {
final String selected = (String) parent
.getItemAtPosition(position);
Toast.makeText(getApplicationContext(), selected,
Toast.LENGTH_SHORT).show();
}

});
}

Toast 显示 array2 中的字符串,我希望它显示 array 中保存的字符串。我怎样才能做到这一点?

最佳答案

 public void populate(ArrayList<String> array, ArrayList<String> array2) {
ListView showList = (ListView) findViewById(R.id.listView1);
SchedAdapter shows = new SchedAdapter(getApplicationContext(),
R.layout.rowlayout, array, array2);
showList.setAdapter(shows);
showList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, final View view,
final int position, long id) {

Toast.makeText(getApplicationContext(), array2.get(position),
Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), array.get(position),
Toast.LENGTH_SHORT).show();
}

});
}

关于java - 具有多个数组的自定义适配器 OnItemClick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22921346/

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