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;
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
add a comment |
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
Usually, I pass the binding object to the holder. The holder then has abind()
function that I call fromonBindViewHolder()
, so I can pass the model/viewmodel data to the holder. The holder then updates the binding object as needed. And, since this is aRecyclerView
, the holder also callsexecutePendingBindings()
on the binding object.
– CommonsWare
Mar 24 at 12:46
sir, can you give a working example?
– Nurseyit
Mar 24 at 12:50
1
trygoogle("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
add a comment |
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
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
android android-recyclerview android-jetpack
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 abind()
function that I call fromonBindViewHolder()
, so I can pass the model/viewmodel data to the holder. The holder then updates the binding object as needed. And, since this is aRecyclerView
, the holder also callsexecutePendingBindings()
on the binding object.
– CommonsWare
Mar 24 at 12:46
sir, can you give a working example?
– Nurseyit
Mar 24 at 12:50
1
trygoogle("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
add a comment |
Usually, I pass the binding object to the holder. The holder then has abind()
function that I call fromonBindViewHolder()
, so I can pass the model/viewmodel data to the holder. The holder then updates the binding object as needed. And, since this is aRecyclerView
, the holder also callsexecutePendingBindings()
on the binding object.
– CommonsWare
Mar 24 at 12:46
sir, can you give a working example?
– Nurseyit
Mar 24 at 12:50
1
trygoogle("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
add a comment |
2 Answers
2
active
oldest
votes
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);
add a comment |
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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);
add a comment |
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);
add a comment |
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);
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);
answered Mar 27 at 6:21
VenkyVenky
6891820
6891820
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Mar 27 at 6:14
NurseyitNurseyit
100110
100110
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Usually, I pass the binding object to the holder. The holder then has a
bind()
function that I call fromonBindViewHolder()
, so I can pass the model/viewmodel data to the holder. The holder then updates the binding object as needed. And, since this is aRecyclerView
, the holder also callsexecutePendingBindings()
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