How to Put String Variable in following Code, Please Help me.
parameters.putString("attachment","{\"name\":\"Facebook application By Martin\",\"href\":\"http://www.google.com/\",\"caption\":\"By Google Technology \",\"description\":\"Description\",\"media\":[{\"type\":\"image\",\"src\":\"http://4.bp.blogspot.com/-9RPH9UGDSsE/TcGjy3fAHlI/AAAAAAAAAeI/kuQXLE_G5Ew/s1600/Flag+Wallpaper+of+India+%25283%2529.jpg\",\"href\":\"http://s.facebook.com/connect.php?tab=iphone/\"}],\"properties\":{\"another link\":{\"text\":\"for more tips click here\",\"href\":\"http://www.google.com/\"}}}");
I use Above Code for Upload Image on Facebook Wall.But i want to use string variable & pass following path from variable.
http://4.bp.blogspot.com/-9RPH9UGDSsE/TcGjy3fAHlI/AAAAAAAAAeI/kuQXLE_G5Ew/s1600/Flag+Wallpaper+of+India+%25283%2529.jpg
Thanks in Advance.
I suggest you to refer this link: String Resources in Android.
Now Just check this example in the given link:
Define the below string inside the strings.xml:
<string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>
Now from activity class, you can get string and pass parameter value as:
Resources res = getResources();
String text = String.format(res.getString(R.string.welcome_messages), username, mailCount);
So this is the basic example for your reference.
You can also define your string value inside the strings.xml and pass the parameter as per your requirement.
String myPath = "http://4.bp.blogspot.com/-9RPH9UGDSsE/TcGjy3fAHlI/AAAAAAAAAeI/kuQXLE_G5Ew/s1600/Flag+Wallpaper+of+India+%25283%2529.jpg";
String myUrl = "parameters.putString("attachment","{\"name\":\"Facebook application By Dipak Keshariya\",\"href\":\"http://www.arthisoft.com/\",\"caption\":\"By Google Technology \",\"description\":\"Description\",\"media\":[{\"type\":\"image\",\"src\":\" + myPath + \",\"href\":\"http://s.facebook.com/connect.php?tab=iphone/\"}],\"properties\":{\"another link\":{\"text\":\"for more tips click here\",\"href\":\"http://www.google.com/\"}}}");
";
Look at how I have changed the url in your call by using the concatenation operator ' + myPath + '
This is very, very basic. You should start learning java if you want to become an Android developer.
On another note, on your picture, top left corner, are you really sure you are a "PROUND" indian ?? :D
Related
Does anyone know a solution for my problem?
I made a editor for my in game Shared Preferences as a Activity. There is a list with all values of one Shared Preferences. But when i write for a textView called value_theme:
value_theme.setText(R.string.editor_div_value + settings_theme);
Android uses an other string resource from an other activity.
When i write
value_theme.setText(R.string.editor_div_value + "" + settings_theme);
the app sets the TextView text to: 21312309366. Does anyone know how to fix that?
Use this:
value_theme.setText(context.getString(R.string.editor_div_value) + "" + settings_theme);
Since you are appending the string, you are mistakenly using the wrong setText method which accepts a CharSequence and sets to the TextView as it is.
Or another way is to do String formatting.
<string name="editor_div_value">Your String value %1$s</string>
To get the String in Java code:
value_theme.setText(context.getString(R.string.editor_div_value, settings_theme));
I have a list containing the following:
String list[]={"Team 1,Apple,Mango,Kiwi","Team 2,Mango,Kiwi,Pineapple","Team 3,Kiwi,Pineapple,Apple"};
my question is, how do you know what each team has? also how do you get the team name?
i would like to have the output:
Team 1,Team 3(Apple,Kiwi)
Team 1,Team 2(Mango,Kiwi)
Team 2,Team 3(Pineapple,Kiwi)
can someone tell me what can be done or what to do?
In order to get the values of the first string in a list of strings you can split the string by "," and put it in a list like following: String s1 [] = list[0].split(","); and then s1[0] is Team1 s1[1] is Apple etc..
You can make use of StringTokenizer to accomplish your task.
http://developer.android.com/reference/java/util/StringTokenizer.html
Everybody knows that if we have:
ekran3.setText("VAT Tax:");
We may (or even we SHOULD) convert it to:
ekran3.setText(getString(R.string.kwotaVat));
and add in strings.xml:
<string name="kwotaVat">VAT Tax:</string>
But is there some kind of trick to do it automatically? For example by clicking RMB on text and selecting some option? It would be nice to know it in fact it will save us a lot of time than while we're doing it manually.
If you are using Eclipse you may extract the string directly into the strings.xml file by placing the mouse within the string and hitting Ctrl + 1. It will bring up the dialog as followed and you may select "Extract String". You then give it a name (Ex: kwotaVat) and you're done.
hey you do not need to use getString() to convert it to string the values xml file is already having data in string form so you just need to use the following code to set the string
ekran3.setText(R.string.kwotaVat);
where ekran3 is the object of your text view
and kwotaVat is the id of your value string
for more detail od android codes have look here http://grabcodes.blogspot.com/
I am having trouble with setting text in a text view with format and multiple values.
holder.car.setText(R.string.mycar + lm.getCarName() + R.string.year + lm.getYear());
this is giving me " 2143545 Camero 2143213 1977 "
I have tried few other "solutions" from the web
holder.car.setText(getString(R.string.mycar) + lm.getCarName() + getString(R.string.year) + lm.getYear()); << not work, getString undefine>>
I even tried String.valueOf(R.string.mycar); getResources().getText(R.String.mycar), still it didn't work.
It would be great if someone can help me, thanks
Try this
holder.car.setText(getResources().getString(R.string.mycar));
I think you're trying to use parameters in your string.
Try this:
<string name="mycar">Car: %1$s Year: %2$s</string>
String mycar = getString(R.string.mycar);
mycar = String.format(mycar, lm.getCarName(), lm.getYear());
You should get:
Car: Camaro Year: 1977
If you want to set your textview just a string from your string.xml file,
mytextview.setText(R.String.mycar);
If you want to set your textview with combination of some strings or integers, (better than first way)
int number=5;
mytextview.setText(getResources().getString(R.String.mycar) + " " +number + " " + getResources().getString(R.String.mysecondcar));
R.string.mycar and R.string.year are only IDs for resources. For this reason you get the numbers (IDs are numeric).
To get string from resources you need to use this construction:
String myCar = getResources().getString(R.string.mycar);
and now the myCar variable holds the string you put in strings.xml file under the mycar name.
the method getResources() belongs to Context. If you run your code outside an Activity, use the context instance to get the string, like this:
String myCar = context.getResources().getString(R.string.mycar);
Try this. If you're fetching string in class without extending Activity Get using your Context
holder.car.setText(context.getResources().getString(R.string.mycar));
If you're extending Activity
holder.car.setText(yourActivity.this.getResources().getString(R.string.mycar));
Hope this helps you..
You have to retrieve your resources first, and the call the medthod getString(int), not getText, has you have put.
So, it should be:
getResources().getString(R.String.mycar);
The R class contains kind of pointers to your ressources, so you can not directly use them, use getResources().getString(), as others say.
I'm creating an android application and within it there is a button that will send some information in an email, and I don't want to have everything all in one paragraph.
Here's what my app is doing for the putExtra for the email's body:
I am the first part of the info being emailed. I am the second part. I am the third part.
Here's what I want it to do:
I am the first part of the info being emailed.
I am the second part.
I am the third part.
How would I put a new line into a string or with the putExtra method to accomplish that?
Try:
String str = "my string \n my other string";
When printed you will get:
my string
my other string
Try using System.getProperty("line.separator") to get a new line.
I would personally prefer using "\n". This just puts a line break in Linux or Android.
For example,
String str = "I am the first part of the info being emailed.\nI am the second part.\n\nI am the third part.";
Output
I am the first part of the info being emailed.
I am the second part.
I am the third part.
A more generalized way would be to use,
System.getProperty("line.separator")
For example,
String str = "I am the first part of the info being emailed." + System.getProperty("line.separator") + "I am the second part." + System.getProperty("line.separator") + System.getProperty("line.separator") + "I am the third part.";
brings the same output as above. Here, the static getProperty() method of the System class can be used to get the "line.seperator" for the particular OS.
But this is not necessary at all, as the OS here is fixed, that is, Android. So, calling a method every time is a heavy and unnecessary operation.
Moreover, this also increases your code length and makes it look kind of messy. A "\n" is sweet and simple.
I use <br> in a CDATA tag.
As an example, my strings.xml file contains an item like this:
<item><![CDATA[<b>My name is John</b><br>Nice to meet you]]></item>
and prints
My name is John
Nice to meet you
If you want to add line break at runtime into a String from same string you are deriving the value then this Kotlin code works for me:
str = "<br>"+str?.replace("," , "</br><br>")+"</br>"
value = HtmlCompat.fromHtml(${skill_et_1}",Html.FROM_HTML_MODE_LEGACY)
tv.text = value