search

Home  >  Q&A  >  body text

android - recyclerview refresh issue

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

仅有的幸福仅有的幸福2771 days ago962

reply all(3)I'll reply

  • 漂亮男人

    漂亮男人2017-05-24 11:40:08

    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:

     mData.get(1).setAvatarUri(photoFile);
                mData.get(1).setType(2);
                notifyItemChanged(1);
                

    Well, it’s exactly the same as the one online. (I hope someone with other methods can answer and give me an idea)

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-24 11:40:08

    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:

    <TextView
            android:drawableRight="@drawable/avatar"
            android:drawablePadding="10dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:textSize="16sp"
            android:text="头像"
            android:background="@color/white"
            android:gravity="center_vertical"
            android:layout_width="match_parent"
            android:layout_height="50dp" />
            

    After clicking the OK button, use:
    setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom) to set a new avatar

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-24 11:40:08

    There 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

    reply
    0
  • Cancelreply