-
Notifications
You must be signed in to change notification settings - Fork 10
How do I access childviews of any layout? I want to change their values programatically. Thanks for building an awesome library. #12
Comments
I am also stuck here. I am trying to change the "text" attribute of child view programmatically but it is not working. |
Hello. If I understand right, the question is how to programmatically acess to JoinableLayout views. So, take a look at Full Demo App onCreateMethod. I use onInflateComplete callback to set on click listeners, like:
"View view" param is the root of your JoinableLayout. |
NOTE: if you're using this method to save links to child views for later changing values (for example, text in TextView), you should be aware of RecyclerView behavior - it can recycle your layout and recreate it later, and all your changes will be lost, so ensure you also bind your current data in onInflateComplete callback |
This is a great library. The recycler view library works fine, expect one thing. Consider the following code snippet:
In reviews.xml layout file I have a TextView with hard coded android:text="Reviews". But, in movie_details layout I want to dynamically populate some TextFields. For example, a movie title, release year, ratings etc. I am inflating the details xml and filling the elements from a DB cursor.
And, then I pull values from a cursor and try to fill the views (using setText etc. APIs). But, this is not working. In the logs, I can see that cursor has the correct value but setText API does not change the text of a TextView. |
Of course, the view you've inflated are not displayed on the screen, because you've not added it. RvJoiner inflates your layout itself, and you should use inflate callback to find your text views, as i wrote in previous comment:
|
Thanks. But I noticed something weird. The onInflateComplete callback is randomly triggered. The following code snippet shows how I am adding and getting references inside the onInflateComplete callback.
And then later in my code I try to set the value of TextView using setText(string) API. I ran the app, it crashed and I got a NullPointerException. The OS killed the app. I restarted the app and again got a NPE. The third time, it worked. So, on first two launches the callback wasn't triggered and the objects were null. |
To be used in RecyclerView, my lib wraps your layout into RecyclerView.Adapter. This callback is called after RecyclerView.Adapter.onCreateViewHolder. It can be called at any time (in our case, at first time) when you scroll list and your layout became visible. So, you can you setText only after this callback. Moreover,
It seems you not clearly understand what happens inside of RecyclerView. This video can be useful. Good luck in your projects! :) |
No description provided.
The text was updated successfully, but these errors were encountered: