Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何更改嵌套listview项中的ImageView资源?_Java_Android_Android Layout_Listview_Android Studio - Fatal编程技术网

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

Java 如何更改嵌套listview项中的ImageView资源?,java,android,android-layout,listview,android-studio,Java,Android,Android Layout,Listview,Android Studio,我有一个listview,它有一个imageview和一些textview。如果单击图像,如何更改imageview资源 如果我理解您的逻辑,您需要: 设置MClickListener 保存在侦听器中选择的位置 设置适配器内图像的onClickListener 使用所选位置从适配器中保存的数据恢复imagem Código Setonitemclick监听器: listView.setOnItemClickListener(new AdapterView.OnItemClickListene

我有一个listview,它有一个imageview和一些textview。如果单击图像,如何更改imageview资源


如果我理解您的逻辑,您需要:

  • 设置MClickListener
  • 保存在侦听器中选择的位置
  • 设置适配器内图像的onClickListener
  • 使用所选位置从适配器中保存的数据恢复imagem
Código Setonitemclick监听器:

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;
    }
});
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
}

我希望这对你有帮助。

你是什么意思?您正在尝试更改您单击的同一图像吗?此外,我们不会为您提供完整的解决方案。你试过什么了吗?没错。当我单击任何图像时,它将变为另一个图像,这很难,但不向我们显示一些代码,基本上我在适配器中单击项目并更改图像,显示适配器我在imageview上添加单击侦听器,但当我单击图像时,两个或更多图像资源也会更改。