Click here to Skip to main content
15,867,895 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I just stopped working on my android app because I am getting numbers instead of words from strings.xml file to my custom adapter i am displaying data in a recyclerView before I started translating my app to other languages everything was fine i am showing data like this:

holder.capital_description_txt.setText("Description: "+String.valueOf(capital_description.get(position)));


I added strings to strings.xml file:
<string name="adapt_capital_desc">Description.</string>

I added string to textView like this:
holder.capital_description_txt.setText(R.string.adapt_capital_desc+": "+String.valueOf(capital_description.get(position)));


This is my view holder class:
class C_ViewHolder extends RecyclerView.ViewHolder {

        TextView capital_id_txt, capital_date_txt, capital_amount_txt, capital_description_txt;
        LinearLayout mainLayout;

        C_ViewHolder(@NonNull View itemView) {
            super(itemView);
            capital_id_txt = itemView.findViewById(R.id.capital_id_txt);
            capital_date_txt = itemView.findViewById(R.id.capital_date_txt);
            capital_amount_txt = itemView.findViewById(R.id.capital_amount_txt);
            capital_description_txt = itemView.findViewById(R.id.capital_description_txt);

            mainLayout = itemView.findViewById(R.id.mainLayout_c);
            //Animate Recyclerview
            Animation translate_anim = AnimationUtils.loadAnimation(context, R.anim.translate_anim);
            mainLayout.setAnimation(translate_anim);
        }

    }


Finally i didn't got the word "description" instead of that i got "2131755039" . Any idea please?

What I have tried:

I tryed this:
String descri = context.getResources().getString(R.string.adapt_capital_desc).toString();


I also tried this:
String date= String.valueOf(context.getResources().getString(R.string.adapt_capital_desc));


Same problem...
Posted
Updated 6-Jun-23 5:37am
Comments
Richard MacCutchan 6-Jun-23 10:33am    
What you got was correct, it is the string representation of the number 2131755039.
brahim farhat (AAD) 6-Jun-23 11:33am    
Ok i solved the problem
brahim farhat (AAD) 6-Jun-23 11:21am    
Solution please?

1 solution

Ok i solved the problem like this :
String description= context.getResources().getString(R.string.adapt_capital_desc);

I posted my own answer if anyone facing the same problem
 
Share this answer
 
Comments
Richard MacCutchan 6-Jun-23 11:41am    
That is just standard syntax for getting a string value.
brahim farhat (AAD) 6-Jun-23 12:19pm    
As I remember and according to android tutorial it says you just have to put
text.setText(R.string.valeu_of_string);

Is not that right?
Richard MacCutchan 6-Jun-23 12:28pm    
No, the name of the string in the XML will return its value. In your XML code you have:
<string name="adapt_capital_desc">Description.</string>

So using R.string.adapt_capital_desc in the Java code will return its value which is "Description.".
brahim farhat (AAD) 6-Jun-23 16:03pm    
Sorry I mean name of string like this:
text.setText(R.string.name_of_string);


And it is exactly what you said above.. so what i missed?

And what is under water means in this site?
Richard MacCutchan 6-Jun-23 16:38pm    
Yes, exactly so. But that is not a "solution" that you have worked out. It is just the correct way to refer to string values in the resources section.

"Under water" just means that you have not posted any messages in the forums.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900