How to instead “View inflate(int resource,ViewGroup root, boolean attachToRoot)” method when the View just a Simple View used “new TextView”?How to add footer to recyclerView by means supportLibraryRecyclerView onCreateViewHolder Return Type Incompatibility With Multiple Custom ViewHoldersWhy does bindViewHolder accept a position as an argument?RecyclerView: how to catch the onClick on an ImageView?How to make one OnClick Listener for different viewHoldersScrolling lagged after applying the typeface in the Recycler view itemsRecycler View position comparisonMultiple Adapters or One Adapter for different lists and objects - Code PerformanceWhy onBindViewHolder index isn't incrementing in Recycler View?How to add child(Product) under a child(Store) in Firebase Database using RecyclerView
Will some rockets really collapse under their own weight?
Is it really Security Misconfiguration to show a version number?
Sum Square Difference, which way is more Pythonic?
How to measure if Scrum Master is making a difference and when to give up
What are the advantages of this gold finger shape?
Do I need to start off my book by describing the character's "normal world"?
Weird resistor with dots around it on the schematic
What is the hottest thing in the universe?
Locked room poison mystery!
Can a Battle Master fighter with Extra Attack use the Commander's Strike maneuver before he throws a net?
Airline power sockets shut down when I plug my computer in. How can I avoid that?
What is a "soap"?
What would it take to get a message to another star?
Why did IBM make the PC BIOS source code public?
Attacking the Hydra
Is there any official ruling on how characters go from 0th to 1st level in a class?
Did Pope Urban II issue the papal bull "terra nullius" in 1095?
Go to last file in vim
Telephone number in spoken words
What is axle tramp?
Solving pricing problem heuristically in column generation algorithm for VRP
Why does this Jet Provost strikemaster have a textured leading edge?
Why do so many people play out of turn on the last lead?
Why are electric shavers specifically permitted under FAR §91.21
How to instead “View inflate(int resource,ViewGroup root, boolean attachToRoot)” method when the View just a Simple View used “new TextView”?
How to add footer to recyclerView by means supportLibraryRecyclerView onCreateViewHolder Return Type Incompatibility With Multiple Custom ViewHoldersWhy does bindViewHolder accept a position as an argument?RecyclerView: how to catch the onClick on an ImageView?How to make one OnClick Listener for different viewHoldersScrolling lagged after applying the typeface in the Recycler view itemsRecycler View position comparisonMultiple Adapters or One Adapter for different lists and objects - Code PerformanceWhy onBindViewHolder index isn't incrementing in Recycler View?How to add child(Product) under a child(Store) in Firebase Database using RecyclerView
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
When I use the Adapter of a RecyclerView to create ViewHolder, the view is just a TextView, so I don't want use LayoutInflate.inflate()
with a layout.xml file. Therefore I create a TextView instance via constructor, but the TextView shows nothing. Now I want know if there is a way to solve this?
- I write
parent.addView(textview)
beforereturn
, but it crashed. - When I write a
layout.xml
and useLayoutInflate.from().inflate()
, it works well.
@Override
public GeekSearchWordItemAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
TextView textView = new TextView(mActivity);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, R.dimen.text_size_medium);
textView.setTextColor(ContextCompat.getColor(mActivity, R.color.text_c6));
return new ViewHolder(textView);
...
@Override
public void onBindViewHolder(@NonNull GeekSearchWordItemAdapter.ViewHolder holder, int position)
LevelBean bean = LList.getElement(mDatas, position);
if (bean != null)
holder.mTxtName.setText(bean.name);
...
static class ViewHolder extends RecyclerView.ViewHolder
private TextView mTxtName;
public ViewHolder(View itemView)
super(itemView);
mTxtName = (TextView) itemView;
android android-recyclerview android-viewholder
add a comment |
When I use the Adapter of a RecyclerView to create ViewHolder, the view is just a TextView, so I don't want use LayoutInflate.inflate()
with a layout.xml file. Therefore I create a TextView instance via constructor, but the TextView shows nothing. Now I want know if there is a way to solve this?
- I write
parent.addView(textview)
beforereturn
, but it crashed. - When I write a
layout.xml
and useLayoutInflate.from().inflate()
, it works well.
@Override
public GeekSearchWordItemAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
TextView textView = new TextView(mActivity);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, R.dimen.text_size_medium);
textView.setTextColor(ContextCompat.getColor(mActivity, R.color.text_c6));
return new ViewHolder(textView);
...
@Override
public void onBindViewHolder(@NonNull GeekSearchWordItemAdapter.ViewHolder holder, int position)
LevelBean bean = LList.getElement(mDatas, position);
if (bean != null)
holder.mTxtName.setText(bean.name);
...
static class ViewHolder extends RecyclerView.ViewHolder
private TextView mTxtName;
public ViewHolder(View itemView)
super(itemView);
mTxtName = (TextView) itemView;
android android-recyclerview android-viewholder
1
are you sure thatbean != null
?
– pskink
Mar 27 at 12:03
1
Don't you have to explicit returnGeekSearchWordItemAdapter.ViewHolder
?
– Haroun Hajem
Mar 27 at 13:41
add a comment |
When I use the Adapter of a RecyclerView to create ViewHolder, the view is just a TextView, so I don't want use LayoutInflate.inflate()
with a layout.xml file. Therefore I create a TextView instance via constructor, but the TextView shows nothing. Now I want know if there is a way to solve this?
- I write
parent.addView(textview)
beforereturn
, but it crashed. - When I write a
layout.xml
and useLayoutInflate.from().inflate()
, it works well.
@Override
public GeekSearchWordItemAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
TextView textView = new TextView(mActivity);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, R.dimen.text_size_medium);
textView.setTextColor(ContextCompat.getColor(mActivity, R.color.text_c6));
return new ViewHolder(textView);
...
@Override
public void onBindViewHolder(@NonNull GeekSearchWordItemAdapter.ViewHolder holder, int position)
LevelBean bean = LList.getElement(mDatas, position);
if (bean != null)
holder.mTxtName.setText(bean.name);
...
static class ViewHolder extends RecyclerView.ViewHolder
private TextView mTxtName;
public ViewHolder(View itemView)
super(itemView);
mTxtName = (TextView) itemView;
android android-recyclerview android-viewholder
When I use the Adapter of a RecyclerView to create ViewHolder, the view is just a TextView, so I don't want use LayoutInflate.inflate()
with a layout.xml file. Therefore I create a TextView instance via constructor, but the TextView shows nothing. Now I want know if there is a way to solve this?
- I write
parent.addView(textview)
beforereturn
, but it crashed. - When I write a
layout.xml
and useLayoutInflate.from().inflate()
, it works well.
@Override
public GeekSearchWordItemAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
TextView textView = new TextView(mActivity);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, R.dimen.text_size_medium);
textView.setTextColor(ContextCompat.getColor(mActivity, R.color.text_c6));
return new ViewHolder(textView);
...
@Override
public void onBindViewHolder(@NonNull GeekSearchWordItemAdapter.ViewHolder holder, int position)
LevelBean bean = LList.getElement(mDatas, position);
if (bean != null)
holder.mTxtName.setText(bean.name);
...
static class ViewHolder extends RecyclerView.ViewHolder
private TextView mTxtName;
public ViewHolder(View itemView)
super(itemView);
mTxtName = (TextView) itemView;
android android-recyclerview android-viewholder
android android-recyclerview android-viewholder
edited Mar 27 at 14:32
Haroun Hajem
1,0601 gold badge9 silver badges19 bronze badges
1,0601 gold badge9 silver badges19 bronze badges
asked Mar 27 at 12:02
li_userli_user
85 bronze badges
85 bronze badges
1
are you sure thatbean != null
?
– pskink
Mar 27 at 12:03
1
Don't you have to explicit returnGeekSearchWordItemAdapter.ViewHolder
?
– Haroun Hajem
Mar 27 at 13:41
add a comment |
1
are you sure thatbean != null
?
– pskink
Mar 27 at 12:03
1
Don't you have to explicit returnGeekSearchWordItemAdapter.ViewHolder
?
– Haroun Hajem
Mar 27 at 13:41
1
1
are you sure that
bean != null
?– pskink
Mar 27 at 12:03
are you sure that
bean != null
?– pskink
Mar 27 at 12:03
1
1
Don't you have to explicit return
GeekSearchWordItemAdapter.ViewHolder
?– Haroun Hajem
Mar 27 at 13:41
Don't you have to explicit return
GeekSearchWordItemAdapter.ViewHolder
?– Haroun Hajem
Mar 27 at 13:41
add a comment |
1 Answer
1
active
oldest
votes
In onCreateViewHolder() try to add layout params to the TextView you creates there.
RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(
RecyclerView.LayoutParams.WRAP_CONTENT, RecyclerView.LayoutParams.WRAP_CONTENT);
textView.setLayoutParams(params);
no, it didn't work... I've tried...
– li_user
Mar 28 at 11:42
Add your xml file to the question, please.
– Alexey
Mar 31 at 10:43
And as psknik wrote, debug and check bean for null.
– Alexey
Mar 31 at 10:44
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%2f55376721%2fhow-to-instead-view-inflateint-resource-viewgroup-root-boolean-attachtoroot%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In onCreateViewHolder() try to add layout params to the TextView you creates there.
RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(
RecyclerView.LayoutParams.WRAP_CONTENT, RecyclerView.LayoutParams.WRAP_CONTENT);
textView.setLayoutParams(params);
no, it didn't work... I've tried...
– li_user
Mar 28 at 11:42
Add your xml file to the question, please.
– Alexey
Mar 31 at 10:43
And as psknik wrote, debug and check bean for null.
– Alexey
Mar 31 at 10:44
add a comment |
In onCreateViewHolder() try to add layout params to the TextView you creates there.
RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(
RecyclerView.LayoutParams.WRAP_CONTENT, RecyclerView.LayoutParams.WRAP_CONTENT);
textView.setLayoutParams(params);
no, it didn't work... I've tried...
– li_user
Mar 28 at 11:42
Add your xml file to the question, please.
– Alexey
Mar 31 at 10:43
And as psknik wrote, debug and check bean for null.
– Alexey
Mar 31 at 10:44
add a comment |
In onCreateViewHolder() try to add layout params to the TextView you creates there.
RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(
RecyclerView.LayoutParams.WRAP_CONTENT, RecyclerView.LayoutParams.WRAP_CONTENT);
textView.setLayoutParams(params);
In onCreateViewHolder() try to add layout params to the TextView you creates there.
RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(
RecyclerView.LayoutParams.WRAP_CONTENT, RecyclerView.LayoutParams.WRAP_CONTENT);
textView.setLayoutParams(params);
answered Mar 27 at 12:35
AlexeyAlexey
3,1391 gold badge20 silver badges27 bronze badges
3,1391 gold badge20 silver badges27 bronze badges
no, it didn't work... I've tried...
– li_user
Mar 28 at 11:42
Add your xml file to the question, please.
– Alexey
Mar 31 at 10:43
And as psknik wrote, debug and check bean for null.
– Alexey
Mar 31 at 10:44
add a comment |
no, it didn't work... I've tried...
– li_user
Mar 28 at 11:42
Add your xml file to the question, please.
– Alexey
Mar 31 at 10:43
And as psknik wrote, debug and check bean for null.
– Alexey
Mar 31 at 10:44
no, it didn't work... I've tried...
– li_user
Mar 28 at 11:42
no, it didn't work... I've tried...
– li_user
Mar 28 at 11:42
Add your xml file to the question, please.
– Alexey
Mar 31 at 10:43
Add your xml file to the question, please.
– Alexey
Mar 31 at 10:43
And as psknik wrote, debug and check bean for null.
– Alexey
Mar 31 at 10:44
And as psknik wrote, debug and check bean for null.
– Alexey
Mar 31 at 10:44
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
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%2f55376721%2fhow-to-instead-view-inflateint-resource-viewgroup-root-boolean-attachtoroot%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
1
are you sure that
bean != null
?– pskink
Mar 27 at 12:03
1
Don't you have to explicit return
GeekSearchWordItemAdapter.ViewHolder
?– Haroun Hajem
Mar 27 at 13:41