我想为listview设置一个动作监听器,以便根据所点击的位置显示具体的细节。但是,在使用getPosition()和getName()方法时遇到错误。请帮助我纠正这种情况,并解释它是如何运作的,因为我很困惑。
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?>adapter, View v, int position, long id) {
String item = yourData.getPosition(position).getName(NAMES);
Intent intentProduct = new Intent(Scrollable.this, ProductDetail.class);
intentProduct.putExtra("Key", item);
startActivity(intentProduct);
}
});
答案 0 :(得分:0)
String item = yourData.getPosition(position).getName(NAMES); // NAMES not nessasry
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?>adapter, View v, int position, long id) {
String item = yourData.getPosition(position).getName();
Intent intentProduct = new Intent(Scrollable.this, ProductDetail.class);
intentProduct.putExtra("Key", item);
startActivity(intentProduct);
}
});
&#13;
答案 1 :(得分:0)
使用此
String item = yourData.getPosition(position).getName();
投入
String item = yourData.getPosition(position).getName(NAMES);
<强>码强>
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?>adapter, View v, int position, long id) {
String item = yourData.getPosition(position).getName();
Intent intentProduct = new Intent(Scrollable.this, ProductDetail.class);
intentProduct.putExtra("Key", item);
startActivity(intentProduct);
}
});