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;








1















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?



  1. I write parent.addView(textview) before return, but it crashed.

  2. When I write a layout.xml and use
    LayoutInflate.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;











share|improve this question





















  • 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

















1















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?



  1. I write parent.addView(textview) before return, but it crashed.

  2. When I write a layout.xml and use
    LayoutInflate.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;











share|improve this question





















  • 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













1












1








1








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?



  1. I write parent.addView(textview) before return, but it crashed.

  2. When I write a layout.xml and use
    LayoutInflate.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;











share|improve this question
















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?



  1. I write parent.addView(textview) before return, but it crashed.

  2. When I write a layout.xml and use
    LayoutInflate.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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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












  • 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







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












1 Answer
1






active

oldest

votes


















0














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





share|improve this answer

























  • 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










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%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









0














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





share|improve this answer

























  • 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















0














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





share|improve this answer

























  • 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













0












0








0







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





share|improve this answer













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






share|improve this answer












share|improve this answer



share|improve this answer










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

















  • 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








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.



















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%2f55376721%2fhow-to-instead-view-inflateint-resource-viewgroup-root-boolean-attachtoroot%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

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현