0

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.

For Example:

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).

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

thanks in advance...

rohit
  • 107
  • 2
  • 7

2 Answers2

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.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)

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

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

Here is the trickiest part.

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)

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

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.

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.

Manikanta
  • 3,421
  • 4
  • 30
  • 51
0

you can use edittext text changed listener for such kind of implementations like updating text as of when editing... for how to implement check this link android on Text Change Listener

Community
  • 1
  • 1
Moulesh
  • 2,762
  • 1
  • 22
  • 32