【发布时间】:2018-11-09 22:45:37
【问题描述】:
我有一个简短的问题。我得到了ListView,它显示了来自ArrayList 的对象。我想要Toast,当我单击列表上的项目时,它可以显示我的对象中的一个值(例如,当我的对象被称为Product 时,我想显示该产品的名称)。我的代码如下所示,我不知道把getProductName() 放在哪里。
final ArrayList<Product> productList = new ArrayList<>();
for(Product p: md.takeAllProducts()){
productList.add(p);
}
ProductListAdapter adapter = new ProductListAdapter(this,R.layout.adapter_view_layout,productList);
mListView.setAdapter(adapter);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(ProductsList.this, mListView.getItemAtPosition(position).toString(),Toast.LENGTH_SHORT).show();
【问题讨论】:
标签: java android listview adapter android-toast