简体   繁体   English

如何在嵌套的listview项中更改ImageView资源?

[英]How to change ImageView resource in nested listview items?

在此处输入图片说明

I have a listview which have a imageview and some textview. 我有一个listview有一个imageview和一些textview。 How can I change imageview resource if I click on a image. 如果我单击图像,如何更改imageview资源。

在此处输入图片说明

If I understood your logic, you need to: 如果我了解您的逻辑,则需要:

  • Set onItemClickListener 设置onItemClickListener
  • save the position selected inside the listener 保存在侦听器中选择的位置
  • set onClickListener of the images inside the adapter 设置适配器内图像的onClickListener
  • use the position selected to recover the imagem from the data saved in the adapter 使用选定的位置从适配器中保存的数据中恢复imagem

Código setOnItemClickListener: 设置setOnItemClickListener:

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        lastSelectedItem = position;
        // Set the collor of the backgroud of the row in the listView, remmember to test if the flag already have been initialized;
    }
});

Código setOnClickListener: 设置setOnClickListener:

onClick(View v){
    // use some field thought the constructor of the adapter
    Drawable draw = data.getImage(lastSelectedItem);
    ImageView img = (ImageView) v;
    img.setDrawable(draw);
    // set the lastSelectedItem and change the color of the background
}

I hope that help you. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM