如何在android的listview中更改另一个edittext值时如何更新edittext值 [英] how to update a edittext value when another edittext value changed inside listview in android

查看:293
本文介绍了如何在android的listview中更改另一个edittext值时如何更新edittext值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有EditText的自定义列表视图,我的问题是当一个edittext值被更改时,我需要在listview内部更新另一个edittext值.

I have a custom listview with EditText, my problem is when one edittext value is alter then i need to update another edittext value in inside listview.

例如:

如果edittext position1的值为'5',并且edittext position2的值为'2',则表示我需要更新特定位置值为'7'(5 + 2 = 7).

if edittext position1 value is '5',and edittext position2 value is '2' means i need to update particular possition value is '7' (5+2=7).

如何在每次其他edittext值更改时不刷新视图呢?

how this possible without refresh the view every time when another edittext value changed?

提前谢谢...

推荐答案

我将给出一个广义的解决方案,而不是0/1等的位置. 因此,要执行此类操作,请执行以下步骤:

I'm going to give a generalised solution instead of the positions for 0/1 etc.. So for performing such operations do the following steps:

1.从ListView更改为RecyclerView. 2.RecyclerView强制开发人员遵循视图持有者模式(我假设您知道什么是视图持有者模式,否则可以谷歌搜索)

1.Change from ListView To RecyclerView. 2.RecyclerView Forces developer to follow view holder pattern (I assume you know what view holder pattern is if not you can google it)

因此,在用户单击行时,在recyclerview中,您将拥有被点击的位置.

So in your recyclerview whenever user clicked on a row you will have the clicked position.

使用以下方法获取特定位置的视图

use the following method to get the view for particular position

myRecyclerView.findViewHolderForAdapterPosition(pos);

此处pos是要在其中编辑edittext值的recyclerview行.

here pos is the recyclerview row where you want to edit the edittext value.

这是最棘手的部分.

由于recyclerview使用viewholder模式,如果不在视口中,则上述方法可能返回null(即,如果在屏幕中看不到)

As recyclerview uses viewholder pattern, the above method may return null if is not in the viewport(i:e; If it is not seen in the screen)

如果myRecyclerView.findViewHolderForAdapterPosition(pos);此方法返回的视图很好(视图当前在池中并且可以访问)

if myRecyclerView.findViewHolderForAdapterPosition(pos); this method returns a view well and good (view is currently in pool and is accessible)

如果不是,则返回null,因此您需要记住该事件,并且当用户滚动时,如果当前显示的位置与要更新的视图匹配,则将获得当前显示的位置,然后更新您的edittext.

If not it returns null, so what you need to do is remember the event and when user scrolls you will get the currently shown position if the currently shown position matches the view to be updated then update your edittext.

实际上,一旦我遇到相同的情况,这就是我解决的方法.

Actually once i faced the same scenario and this is how i solved it.

如果有任何疑问,请在下面评论.

Comment below if you have any doubts.

如果列表中只有两行,我认为. myRecyclerView.findViewHolderForAdapterPosition(pos);除非您的每一行都是屏幕大小,否则此方法将永远不会返回false.

I case if you have only two rows in a list . myRecyclerView.findViewHolderForAdapterPosition(pos); this method will never return false unless your each row is of screen size.

这篇关于如何在android的listview中更改另一个edittext值时如何更新edittext值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆