R.string.Converasation contains Conversation Here is the code
tv.setText(R.string.Converasation+"HELLo");
textview view is taking int value of R.string.Converasation and string value of HELLo and finally displays 2131034187Hello but i want ConverasationHello
how to resolve this..
java file, first of all, we access the TextView from the xml file by the line "TextView txtView = findViewById(R. id. text_view);" and in the next line we set the text by the line "txtView. setText("Android TextView");" .
String. xml file contains all the strings which will be used frequently in Android project. String. xml file present in the values folder which is sub folder of res folder in project structure.In Android Studio, we have many Views such as TextView,Button,EditText,CheckBox,RadioButton etc.
Note: A string is a simple resource that is referenced using the value provided in the name attribute (not the name of the XML file). So, you can combine string resources with other simple resources in the one XML file, under one <resources> element. file location: res/values/filename.xml.
Textview : should be used for uneditable text which user wants to read but not to manipulate. e.g. News, Articles, Blogs. Plain text/ Edittext : should be used for taking user input in alphanumeric form. e.g. UserId, Comments.
Try
tv.setText(getString(R.string.Converasation) + "HELLo");
Marc.
It should be like:
tv.setText(getString(R.string.Converasation)+" Hello ");
FYI, You can use either getString(int) or getText(int) to retrieve a string.
@Mudassir everything works great. for me it's:
display.setText(getText(R.string.counting_result) + " "+ counter);
Try following code:
Resources res = context.getResources();
float floatConverasation = 1.1f;
String strfloatConverasation = "HELLO";
tv.setText(String.format(Locale.ENGLISH,"%s %f %s",
res.getString(R.string.conversation), floatConverasation, strfloatConverasation));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With