how to use recycleView with databinding library?How to save an Android Activity state using save instance state?How do I center text horizontally and vertically in a TextView?Why is the Android emulator so slow? How can we speed up the Android emulator?How do I fix android.os.NetworkOnMainThreadException?How to add dividers and spaces between items in RecyclerView?Using custom view in RecyclerView widgetI need an explanation of View TypeRecycler View position comparisonDataBinding With RecycleView Exception: ParentView is existedHow does Recycler view draw individual rows

Creating Fictional Slavic Place Names

What does War Machine's "Canopy! Canopy!" line mean in "Avengers: Endgame"?

Is there a rule that prohibits us from using 2 possessives in a row?

Explain Ant-Man's "not it" scene from Avengers: Endgame

Is it a problem that pull requests are approved without any comments

Did thousands of women die every year due to illegal abortions before Roe v. Wade?

How do I remove hundreds of automatically added network printers?

Please help me identify this plane

How is it possible for this NPC to be alive during the Curse of Strahd adventure?

Is the capacitor drawn or wired wrongly?

What is the best option to connect old computer to modern TV

Applicants clearly not having the skills they advertise

Chopin: marche funèbre bar 15 impossible place

What is the correct expression of 10/20, 20/30, 30/40 etc?

Can a class take a different class's spell in their ritual book?

Restoring order in a deck of playing cards (II)

Filling region bounded by multiple paths

Opposite of "Squeaky wheel gets the grease"

Why does MS SQL allow you to create an illegal column?

Can an old DSLR be upgraded to match modern smartphone image quality

Will dual-learning in a glider make my airplane learning safer?

The term for the person/group a political party aligns themselves with to appear concerned about the general public

Why is Colorado so different politically from nearby states?

Are there practical reasons to NOT use a stepper motor with lead screw for the X and or Y axes?



how to use recycleView with databinding library?


How to save an Android Activity state using save instance state?How do I center text horizontally and vertically in a TextView?Why is the Android emulator so slow? How can we speed up the Android emulator?How do I fix android.os.NetworkOnMainThreadException?How to add dividers and spaces between items in RecyclerView?Using custom view in RecyclerView widgetI need an explanation of View TypeRecycler View position comparisonDataBinding With RecycleView Exception: ParentView is existedHow does Recycler view draw individual rows






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I want to make recycle view with ViewModel and data binding following MVVM principle. But I don't know how to create data binding in onCreateViewHolder(). What I should do?



override fun onCreateViewHolder(parent: ViewGroup,
viewType: Int): MyAdapter.MyViewHolder
// create a new view
val inflator = LayoutInflater.from(parent.context)

val listItemBinding :ResItemBinding = DataBindingUtil.inflate(inflator, R.layout.res_item, parent, false)
// set the view's size, margins, paddings and layout parameters
return MyViewHolder(listItemBinding.root)



I tried the above solution but it does not work properly










share|improve this question
























  • Usually, I pass the binding object to the holder. The holder then has a bind() function that I call from onBindViewHolder(), so I can pass the model/viewmodel data to the holder. The holder then updates the binding object as needed. And, since this is a RecyclerView, the holder also calls executePendingBindings() on the binding object.

    – CommonsWare
    Mar 24 at 12:46











  • sir, can you give a working example?

    – Nurseyit
    Mar 24 at 12:50






  • 1





    try google("recyclerview databinding") - it returns a lot of samples

    – pskink
    Mar 24 at 12:51












  • github.com/commonsguy/cw-omnibus/tree/FINAL/DataBinding/…

    – CommonsWare
    Mar 24 at 12:51

















0















I want to make recycle view with ViewModel and data binding following MVVM principle. But I don't know how to create data binding in onCreateViewHolder(). What I should do?



override fun onCreateViewHolder(parent: ViewGroup,
viewType: Int): MyAdapter.MyViewHolder
// create a new view
val inflator = LayoutInflater.from(parent.context)

val listItemBinding :ResItemBinding = DataBindingUtil.inflate(inflator, R.layout.res_item, parent, false)
// set the view's size, margins, paddings and layout parameters
return MyViewHolder(listItemBinding.root)



I tried the above solution but it does not work properly










share|improve this question
























  • Usually, I pass the binding object to the holder. The holder then has a bind() function that I call from onBindViewHolder(), so I can pass the model/viewmodel data to the holder. The holder then updates the binding object as needed. And, since this is a RecyclerView, the holder also calls executePendingBindings() on the binding object.

    – CommonsWare
    Mar 24 at 12:46











  • sir, can you give a working example?

    – Nurseyit
    Mar 24 at 12:50






  • 1





    try google("recyclerview databinding") - it returns a lot of samples

    – pskink
    Mar 24 at 12:51












  • github.com/commonsguy/cw-omnibus/tree/FINAL/DataBinding/…

    – CommonsWare
    Mar 24 at 12:51













0












0








0








I want to make recycle view with ViewModel and data binding following MVVM principle. But I don't know how to create data binding in onCreateViewHolder(). What I should do?



override fun onCreateViewHolder(parent: ViewGroup,
viewType: Int): MyAdapter.MyViewHolder
// create a new view
val inflator = LayoutInflater.from(parent.context)

val listItemBinding :ResItemBinding = DataBindingUtil.inflate(inflator, R.layout.res_item, parent, false)
// set the view's size, margins, paddings and layout parameters
return MyViewHolder(listItemBinding.root)



I tried the above solution but it does not work properly










share|improve this question
















I want to make recycle view with ViewModel and data binding following MVVM principle. But I don't know how to create data binding in onCreateViewHolder(). What I should do?



override fun onCreateViewHolder(parent: ViewGroup,
viewType: Int): MyAdapter.MyViewHolder
// create a new view
val inflator = LayoutInflater.from(parent.context)

val listItemBinding :ResItemBinding = DataBindingUtil.inflate(inflator, R.layout.res_item, parent, false)
// set the view's size, margins, paddings and layout parameters
return MyViewHolder(listItemBinding.root)



I tried the above solution but it does not work properly







android android-recyclerview android-jetpack






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 6:29









Tanveer Munir

1,7051422




1,7051422










asked Mar 24 at 12:37









NurseyitNurseyit

100110




100110












  • Usually, I pass the binding object to the holder. The holder then has a bind() function that I call from onBindViewHolder(), so I can pass the model/viewmodel data to the holder. The holder then updates the binding object as needed. And, since this is a RecyclerView, the holder also calls executePendingBindings() on the binding object.

    – CommonsWare
    Mar 24 at 12:46











  • sir, can you give a working example?

    – Nurseyit
    Mar 24 at 12:50






  • 1





    try google("recyclerview databinding") - it returns a lot of samples

    – pskink
    Mar 24 at 12:51












  • github.com/commonsguy/cw-omnibus/tree/FINAL/DataBinding/…

    – CommonsWare
    Mar 24 at 12:51

















  • Usually, I pass the binding object to the holder. The holder then has a bind() function that I call from onBindViewHolder(), so I can pass the model/viewmodel data to the holder. The holder then updates the binding object as needed. And, since this is a RecyclerView, the holder also calls executePendingBindings() on the binding object.

    – CommonsWare
    Mar 24 at 12:46











  • sir, can you give a working example?

    – Nurseyit
    Mar 24 at 12:50






  • 1





    try google("recyclerview databinding") - it returns a lot of samples

    – pskink
    Mar 24 at 12:51












  • github.com/commonsguy/cw-omnibus/tree/FINAL/DataBinding/…

    – CommonsWare
    Mar 24 at 12:51
















Usually, I pass the binding object to the holder. The holder then has a bind() function that I call from onBindViewHolder(), so I can pass the model/viewmodel data to the holder. The holder then updates the binding object as needed. And, since this is a RecyclerView, the holder also calls executePendingBindings() on the binding object.

– CommonsWare
Mar 24 at 12:46





Usually, I pass the binding object to the holder. The holder then has a bind() function that I call from onBindViewHolder(), so I can pass the model/viewmodel data to the holder. The holder then updates the binding object as needed. And, since this is a RecyclerView, the holder also calls executePendingBindings() on the binding object.

– CommonsWare
Mar 24 at 12:46













sir, can you give a working example?

– Nurseyit
Mar 24 at 12:50





sir, can you give a working example?

– Nurseyit
Mar 24 at 12:50




1




1





try google("recyclerview databinding") - it returns a lot of samples

– pskink
Mar 24 at 12:51






try google("recyclerview databinding") - it returns a lot of samples

– pskink
Mar 24 at 12:51














github.com/commonsguy/cw-omnibus/tree/FINAL/DataBinding/…

– CommonsWare
Mar 24 at 12:51





github.com/commonsguy/cw-omnibus/tree/FINAL/DataBinding/…

– CommonsWare
Mar 24 at 12:51












2 Answers
2






active

oldest

votes


















2














You can use data binding as below



private YourAdapterBinding mYourAdapterBinding

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
mYourAdapterBinding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),R.layout.your_custome_layout,parent,false);
View itemView = mYourAdapterBinding.getRoot();
return new ViewHolder(itemView);



@Override
public void onBindViewHolder(ViewHolder viewHolder, int position)

Guide guide = mGuideOptionList.get(position);
viewHolder.textView.setText(mYourAdapterList.get(position).getTitle());
viewHolder.parent.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
mYourListItem.onItemClick((int) v.getTag(),v);

);

mYourAdapterBinding.executePendingBindings();



@Override
public long getItemId(int position)
return super.getItemId(position);






share|improve this answer






























    0














    after searching for 3 days I could not find anything suitable for me. But the JetPack Sunflower app used databinding with ListAdapter. So if anyone faced this problem use ListAdapter instead of Adapter. Hope it helps someone






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55323868%2fhow-to-use-recycleview-with-databinding-library%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      You can use data binding as below



      private YourAdapterBinding mYourAdapterBinding

      @Override
      public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
      mYourAdapterBinding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),R.layout.your_custome_layout,parent,false);
      View itemView = mYourAdapterBinding.getRoot();
      return new ViewHolder(itemView);



      @Override
      public void onBindViewHolder(ViewHolder viewHolder, int position)

      Guide guide = mGuideOptionList.get(position);
      viewHolder.textView.setText(mYourAdapterList.get(position).getTitle());
      viewHolder.parent.setOnClickListener(new View.OnClickListener()
      @Override
      public void onClick(View v)
      mYourListItem.onItemClick((int) v.getTag(),v);

      );

      mYourAdapterBinding.executePendingBindings();



      @Override
      public long getItemId(int position)
      return super.getItemId(position);






      share|improve this answer



























        2














        You can use data binding as below



        private YourAdapterBinding mYourAdapterBinding

        @Override
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
        mYourAdapterBinding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),R.layout.your_custome_layout,parent,false);
        View itemView = mYourAdapterBinding.getRoot();
        return new ViewHolder(itemView);



        @Override
        public void onBindViewHolder(ViewHolder viewHolder, int position)

        Guide guide = mGuideOptionList.get(position);
        viewHolder.textView.setText(mYourAdapterList.get(position).getTitle());
        viewHolder.parent.setOnClickListener(new View.OnClickListener()
        @Override
        public void onClick(View v)
        mYourListItem.onItemClick((int) v.getTag(),v);

        );

        mYourAdapterBinding.executePendingBindings();



        @Override
        public long getItemId(int position)
        return super.getItemId(position);






        share|improve this answer

























          2












          2








          2







          You can use data binding as below



          private YourAdapterBinding mYourAdapterBinding

          @Override
          public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
          mYourAdapterBinding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),R.layout.your_custome_layout,parent,false);
          View itemView = mYourAdapterBinding.getRoot();
          return new ViewHolder(itemView);



          @Override
          public void onBindViewHolder(ViewHolder viewHolder, int position)

          Guide guide = mGuideOptionList.get(position);
          viewHolder.textView.setText(mYourAdapterList.get(position).getTitle());
          viewHolder.parent.setOnClickListener(new View.OnClickListener()
          @Override
          public void onClick(View v)
          mYourListItem.onItemClick((int) v.getTag(),v);

          );

          mYourAdapterBinding.executePendingBindings();



          @Override
          public long getItemId(int position)
          return super.getItemId(position);






          share|improve this answer













          You can use data binding as below



          private YourAdapterBinding mYourAdapterBinding

          @Override
          public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
          mYourAdapterBinding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),R.layout.your_custome_layout,parent,false);
          View itemView = mYourAdapterBinding.getRoot();
          return new ViewHolder(itemView);



          @Override
          public void onBindViewHolder(ViewHolder viewHolder, int position)

          Guide guide = mGuideOptionList.get(position);
          viewHolder.textView.setText(mYourAdapterList.get(position).getTitle());
          viewHolder.parent.setOnClickListener(new View.OnClickListener()
          @Override
          public void onClick(View v)
          mYourListItem.onItemClick((int) v.getTag(),v);

          );

          mYourAdapterBinding.executePendingBindings();



          @Override
          public long getItemId(int position)
          return super.getItemId(position);







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 27 at 6:21









          VenkyVenky

          6891820




          6891820























              0














              after searching for 3 days I could not find anything suitable for me. But the JetPack Sunflower app used databinding with ListAdapter. So if anyone faced this problem use ListAdapter instead of Adapter. Hope it helps someone






              share|improve this answer



























                0














                after searching for 3 days I could not find anything suitable for me. But the JetPack Sunflower app used databinding with ListAdapter. So if anyone faced this problem use ListAdapter instead of Adapter. Hope it helps someone






                share|improve this answer

























                  0












                  0








                  0







                  after searching for 3 days I could not find anything suitable for me. But the JetPack Sunflower app used databinding with ListAdapter. So if anyone faced this problem use ListAdapter instead of Adapter. Hope it helps someone






                  share|improve this answer













                  after searching for 3 days I could not find anything suitable for me. But the JetPack Sunflower app used databinding with ListAdapter. So if anyone faced this problem use ListAdapter instead of Adapter. Hope it helps someone







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 27 at 6:14









                  NurseyitNurseyit

                  100110




                  100110



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55323868%2fhow-to-use-recycleview-with-databinding-library%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                      Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript