Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.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项目中单击按钮后,Android获取POJO_Java_Android_Listview - Fatal编程技术网

Java 在listview项目中单击按钮后,Android获取POJO

Java 在listview项目中单击按钮后,Android获取POJO,java,android,listview,Java,Android,Listview,我在一个列表中有一个ImageButton,这样查看孩子们: <ImageButton android:id="@+id/pick_up_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="@dimen/feed_item_padding_left_right" android

我在一个列表中有一个
ImageButton
,这样查看孩子们:

 <ImageButton 
      android:id="@+id/pick_up_button"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:paddingLeft="@dimen/feed_item_padding_left_right"
      android:background="@null"
      android:onClick="pickUpDropOff"/>
pickUpButton.setTag(R.integer.LIST_ITEM_POSITION, position);

这确实会改变图像资源,但当视图被回收时,图像资源中的更改不会持续,因为我的POJO attribute for
pickedUp
尚未更改。在这种情况下,如何获取POJO以更改属性?

在这样更改POJO数据源后,只需调用listview适配器上的notifydatasetchange()

adapter.notifyDataSetChanged()

我把它整理好了

要获取单击按钮的pojo,请在适配器中设置一个标记,对象位置如下:

 <ImageButton 
      android:id="@+id/pick_up_button"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:paddingLeft="@dimen/feed_item_padding_left_right"
      android:background="@null"
      android:onClick="pickUpDropOff"/>
pickUpButton.setTag(R.integer.LIST_ITEM_POSITION, position);
然后单击按钮时,我会像这样更改底层pojo(我的型号是
ShoppingListItem
):


这将通过回收列表视图停止非持久性数据的问题。对我来说,这些数据没有本地存储(都是通过JSON api来的和去的)。如果应用程序调用数据库,请确保保留对数据库的更改。

您可以创建一个变量来控制图像资源(数组),并重写列表适配器的getView()方法来处理列表中的行。只更改pojo的属性不是更简单吗?是的,我知道如何使用
notifyDataSetChanged()
,但我没有改变数据集。这就是我的问题所在-如何更改所单击按钮对应pojo的属性。你看过问题了吗?