Created a recyclerview to set personal information. As shown below:
After clicking, a prompt will appear as shown below:
After the selection is completed, the user chooses to confirm or cancel the reselection, as shown below:
After the selection is confirmed, it returns to the recyclerview. How to update this change? (The picture is the default value in the xml file. How should it be updated to the one selected by the user?)
Already solved. At first I wanted to find a way to refresh the recyclerview without changing the data set data. But in the end it seemed that there was no other way.
So I created a new data set class (very common, data content, set, get methods). Initialize data in the activity calling recyclerview.
Because I returned the activity after calling the system camera. Therefore, a new method is created in the activity to call the activity that determines the interface in the picture above. Used to notify the recyclerview adapter that the data of this item has been updated. In adapter:
Well, it’s exactly the same as the one online. (I hope someone with other methods can answer and give me an idea)
You think it’s too complicated. Using recyclerview is a bit overkill. You have to write a lot more code. Just use TextView directly. Click the OK button and set the image directly. How simple.
xml:
After clicking the OK button, use:
setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom)
to set a new avatarThere are several plans for reference. Our app does this kind of business step by step
Use startActivityForResult(). After the image selection is completed, pass the uri and position to the previous activity, then change the uri in the data according to the position and refresh the data
Use broadcast, customize a broadcast that can receive uri and position, register on the list page, send the broadcast after selecting the picture, and then operate the same as above
Use event bus, we choose EventBus, register Event on the list page, select the picture and send the corresponding message
We initially used startActivityForResult and broadcast mainly to avoid introducing third-party libraries. At the same time, the two pages did not directly call each other and reduced the coupling. However, as more and more similar businesses became available in the later period, such as clicking on favorites and adding comments on the details page, The list page needs to refresh the number of comments and collections... Using these two methods will cause more and more redundant code, so we introduced EventBus, which not only reduces the amount of code, but also increases the readability of the code and reduces the The code is coupled, and this library is quite small and easy to use. It is recommended that the subject use this library directly