android-viewholder

Item in RecyclerView not aligning as expected

眉间皱痕 提交于 2021-02-07 08:47:15
问题 My app has a chat activity which contains a recyclerview. This recyclerview contains two items that display the messages received by the user and the messages sent by the user. The messages received by the user is aligning from the left of the recyclerview as expected but the messages sent by the user is not aligning from the right of the recyclerview as expected. This is how it looks right now: The blue colored messages are the messages received and the gray colored messages are the messages

Item in RecyclerView not aligning as expected

為{幸葍}努か 提交于 2021-02-07 08:43:28
问题 My app has a chat activity which contains a recyclerview. This recyclerview contains two items that display the messages received by the user and the messages sent by the user. The messages received by the user is aligning from the left of the recyclerview as expected but the messages sent by the user is not aligning from the right of the recyclerview as expected. This is how it looks right now: The blue colored messages are the messages received and the gray colored messages are the messages

ViewHolder views must not be attached when created

江枫思渺然 提交于 2021-02-04 14:28:29
问题 I'm trying to create a simple RV that will show a TextView. This is my adapter: public class MyRvAdapter extends RecyclerView.Adapter<MyRvAdapter.ViewHolder> { private String[] mDataset; public static class ViewHolder extends RecyclerView.ViewHolder { // each data item is just a string in this case public TextView mTextView; public ViewHolder(TextView v) { super(v); mTextView = v; } } public MyRvAdapter(String[] myDataset) { mDataset = myDataset; } @NonNull @Override public MyRvAdapter

In Android Kotlin, what's the right way to pass a onclick event into a viewholder?

感情迁移 提交于 2021-01-29 06:00:41
问题 Is there any difference in these two ways? I've been using the seond way and it works so far, yet I found the first way upon reading tutorial articles. 1st: class FlowersAdapter(private val onClick: (Flower) -> Unit) : ListAdapter<Flower, FlowersAdapter.FlowerViewHolder>(FlowerDiffCallback) { /* ViewHolder for Flower, takes in the inflated view and the onClick behavior. */ class FlowerViewHolder(itemView: View, val onClick: (Flower) -> Unit) : RecyclerView.ViewHolder(itemView) { private val

Deleting Card from RecyclerView and re-add it again

∥☆過路亽.° 提交于 2021-01-29 05:34:21
问题 I'm struggling to implement the funtionality to delete an entry of a recyclerview and re-add it again, if the user decided otherwise. For that I'm showing a Snackbar with an undo action. So the flow should be: The user sees a list of Cards which each show some values and an delete button. If the user presses the delete button, the card is deleted and a Snackbar is shown. If the user clicks undo on the Snackbar the Card should be re-added to the RecyclerView . Only if the Snackbar disappears

RecyclerView - changing selected item icon needs two clicks to work

落爺英雄遲暮 提交于 2021-01-28 06:08:10
问题 I am working on a mailing app, in which user can send the same mail to multiple contacts. When I open the contacts list I want to be able to click on the user and his profile picture should be replaced with checked icon. When I click to select a user the icon flickers and it does not change the first time I click on it . Second time I click on it the image still flickers, but then changes to checked , and every next time I click on that user it will flicker but do what I want - become checked

Dynamically Tint drawable in adapter change color for all

試著忘記壹切 提交于 2020-08-11 03:06:05
问题 I get an array of strings from my server using a volley connection. Every single string contain a different color in hex. I use this color to set Tint of a drawable in adapter. Here my code in adapter: @Override public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) { // Get item from position MyObject object = array_data.get(position); ... ... Drawable unwrappedDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_beenhere_black_24dp); Drawable

Dynamically Tint drawable in adapter change color for all

浪子不回头ぞ 提交于 2020-08-11 03:05:20
问题 I get an array of strings from my server using a volley connection. Every single string contain a different color in hex. I use this color to set Tint of a drawable in adapter. Here my code in adapter: @Override public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) { // Get item from position MyObject object = array_data.get(position); ... ... Drawable unwrappedDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_beenhere_black_24dp); Drawable