I want to use links in android dialog and i ran into this weird problem, if i use this:
String part1 = "http://google.com";
String part2Label = "http://tests.fr";
tx1.setText(Html.fromHtml("" + part1Label + "<br>" ) );
tx1.setAutoLinkMask(RESULT_OK);
tx1.setMovementMethod(LinkMovementMethod.getInstance());
It works, but if i change the part1Label to "normal text", it stops working.
Did anyone ran into this issue before? I thought just using Html.fromHtml takes care to interpret of any html elements that i would like to use.
Thank you
I don't know if it's related (since you've said it works in the first option), but you have a couple of "" missing:
tx1.setText(Html.fromHtml("" + part1Label + "<br>" ) );
should be:
tx1.setText(Html.fromHtml("" + part1Label + "<br>" ) );
Related
I'm having a problem with searchText() function used with Robotium.
I'm searching for this string:
<string name="provisioning_wizard_title_2">Service Activation Wizard (Step 2)</string>
I defined it in string xml, and I'm searching it this way:
Activity act=solo.getCurrentActivity();
String string = solo.getString(act.getResources().getIdentifier("provisioning_wizard_title_2", "string", act.getPackageName()));
It fails when I call
assertTrue(solo.searchText(string));
and it fails also if i call:
assertTrue(solo.searchText("Service Activation Wizard (Step 2)"));
even if that is the string I'm seeing in the focused screen activity.
The strange thing is that it works if I use the same string without last character:
assertTrue(solo.searchText("Service Activation Wizard (Step 2"));
and it works if I use
assertTrue(solo.searchText(string.substring(0, string.length()-1)));
I hope someone could help me.
Sorry for my english!
Thank you.
PROBLEM SOLVED
I solved problem thanks to Renas Reda (Founder and maintainer of Robotium).
The problem is due to regex support in searchText(); some characters will trigger it.
Use Pattern.quote(string)
Example: Pattern.qoute("provisioning_wizard_title_2") and eveything works good!
I usually use Solo#waitForText(...) so I make sure I'm not losing some race condition.
Try this:
assertTrue(solo.waitForText( solo.getString(R.string. provisioning_wizard_title_2) );
Make sure you are importing the correct R.java file from your production project (not the test project).
I'm not sure, what string you are fetching. Try to log it:
Log.d("Debug", "String is: " + string);
you should rather call, here may be another issue related to package as activity may be in another package than main package of application:
String string = solo.getString(act.getResources().getIdentifier(act.getPackageName()+":string/provisioning_wizard_title_2"), null, null));
You can also get all visible texts, to make sure, what is on the screen:
for(TextView textView : solo.getCurrentViews(TextView.class)) {
Log.d("DEBUG", "Text on the screen: " + textView.getText().toString());
}
This question already has answers here:
Is it possible to have multiple styles inside a TextView?
(20 answers)
Closed 9 years ago.
In one textview I'm trying to separate text stylings on different words.
So far I have:
textview.setText(Html.fromHtml("<i><small><font color=\"c5c5c5\">" + "Competitor ID: " + "</font></small></i>" + "<font color=\"47a842\">" + compID + "</font>"));
Basically, I'm saying I want "Competitor ID:" to be italic, small, and grey.
And I want that string compID to be normal sized, not italic, and green.
The italic and small portions of the code work perfectly, but for some reason, the entire text view has grey text, rather than just "Competitor ID:".
Any ideas?
textview.setText(Html.fromHtml("<i><small><font color=\"#c5c5c5\">" + "Competitor ID: " + "</font></small></i>" + "<font color=\"#47a842\">" + compID + "</font>"));
Try the above.
Try using one of these grey hex code values instead.
gray1 #030303
gray2 #050505
gray3 #080808
gray4 #0A0A0A
gray5 #0D0D0D
. Also try to control the text color inside the xml textview properties using the above codes. Hope this helps
Hi im invoking a simple progress bar in android with the following code
MyDialog = ProgressDialog.show(attraction_more_info.this, " " ,
" Loading. Please wait ... ", true);
The thing is when it comes up there is a small white circle with a white triangle in it above the spinning icon. How do i get rid of this so it is only the spinning circle and the text.
it looks like the following image although myne does not say the "indeterminate" part.
(source: lytsing.org)
Probably something simple to get rid of it.
Thanks
Remove the space in between the "" after attraction_more_info.this. It's the title. You can enter anything within the double quotes but its optional. E.g. Retrieving Information
From this:
MyDialog = ProgressDialog.show(attraction_more_info.this, " " ,
" Loading. Please wait ... ", true);
Into this:
MyDialog = ProgressDialog.show(attraction_more_info.this, "" ,
" Loading. Please wait ... ", true);
Go for this instead,
MyDialog = ProgressDialog.setMessage("Loading. Please wait...");
This will provide you with your expected result.
I decided to learn a little bit android progrramming and by using Eclipse + android plug-in I made an android "hello world" application. After that I tryed something simple and used 3 TextViews:
ID:TextView1 String-Value:A=5
ID:TextView2 String-Value:B=10
ID:TextView3 String-Value:A+B=C=
I created them in main.xml menu by drag and drop so, to show them I'm using the flowing line:
setContentView(R.layout.main);
The Question is: I want to get string values of A and B and append the result of 5+10 to the string value of C actualy I did it but it take too much codes just for get str value of a TextView and editing it. Is there any short way like in .Net?
string Str = This.Label1.Text();
And is eclipse is the best IDE or am I should use something else?
When I have several textviews etc, Why am I should write unnecessary lines if there is a short way to do it.
Another Question is I get str-value of B which is 10 but when I tryed the same thing for A it says there is nothing inside VarAStr
*My Codes are:*
setContentView(R.layout.main);
TextView VarAStr = (TextView)findViewById(R.id.VarA);
TextView VarBStr = (TextView)findViewById(R.id.VarB);
TextView VarC = (TextView) findViewById(R.id.VarC);
try{
int VarA=Integer.parseInt(VarAStr.getText().toString().substring(2));
int VarB=Integer.parseInt(VarBStr.getText().toString().substring(2));
VarC.append(String.format("%d", (VarA+VarB)));
}
catch(Exception e){
Toast.makeText(this, e.toString() + " -" + VarAStr.getText().toString() + "-", Toast.LENGTH_LONG).show();//Show();
}
For the last question I found a bad code line in main.xml :) wich has no android:text="#string/VarA" I added this and problem solved.
Thank you for any respond.
You can always put the repeated code on a function that returns a string.
Something like:
public String getTextOfView(int id) {
TextView tmp = (TextView)findViewById(id);
return tmp.getText.toString();
}
I have to add text to a button bolding the first line and unbolding the second but i cant figure out which new line character it is.
b.setText(Html.fromHtml("<b>" + st + "<\b>" + "\n" + cursor.getString(1)));
ive also tried
b.setText(Html.fromHtml("<b>" + st + "<\b>" + "<br/>" + cursor.getString(1)));
the second one works but both lines are bolded.
Thanks in advance
wrong end tag:
b.setText(Html.fromHtml("<b>" + st + "</b>" + "<br/>" + cursor.getString(1)));
Rather than using HTML to format your text (which is relatively slow) you could use Spans which give you much tighter control, and are more efficient. I wrote a blog post about the use of spans which may help you to get started.