android spell checking - android

I am trying to check the spelling of a word in code using the api's for ics.
I have used the spell checker sample as a starting point and using this I can get a list of suggested words based on the query word, however I can't see how just to check that the word is spelled correctly.
I have the code below from the example and using this I can see and check the suggestions but not the original word.
#Override
public void onGetSuggestions(final SuggestionsInfo[] arg0) {
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < arg0.length; ++i) {
// Returned suggestions are contained in SuggestionsInfo
final int len = arg0[i].getSuggestionsCount();
sb.append('\n');
for (int j = 0; j < len; ++j) {
sb.append("," + arg0[i].getSuggestionAt(j));
}
sb.append(" (" + len + ")");
}
runOnUiThread(new Runnable(){
#Override
public void run(){
if(arg0[0].getSuggestionsAttributes()==SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY){
mMainView.append(sb.toString());
}
}
});
}
I have added the if statement that checks for RESULT_ATTR_IN_THE_DICTIONARY but I don't know if this is checking the original word or the first suggestion. (If I enter 'ton' as a query I get 'ten' returned however if I enter 'twn' as a query I get no words returned)
What I really need is for either a correct word or empty string to be returned to a query.
Any help would be appreciated,
Thanks

for (int j = 0; j < len; ++j) {
if(arg0[i].getSuggestionAt(j).toString().contains(string)){
sb.append("," + arg0[i].getSuggestionAt(j));
Log.e("check if", ""+arg0[i].getSuggestionAt(j));
}else{
sb.append("" );
Log.e("check", ""+arg0[i].getSuggestionAt(j));
}
}
Try with this code
and also remove
if(arg0[0].getSuggestionsAttributes()==SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY){
mMainView.append(sb.toString());
}
if condition just put mMainView.append(sb.toString());
hope it's useful to you.

Related

Get first argument in live-template

Recently i was creating my own live-template, i was customizing for loop, here is how default for loop is given in live-template.
for(int $INDEX$ = 0; $INDEX$ < $LIMIT$; $INDEX$++) {
$END$
}
but i want my method's first argument inplace of $LIMIT$, how can i do that?
public void getList(ArrayList<String> list)
{
}
then my for loop shoulde be
for(int i = 0; i < list.size; i++) {
...
}
I have seen template of logm, but it is printing all arguments of method
groovyScript("'\"' + _1.collect { it + ' = [\" + ' + it + ' + \"]'}.join(', ') + '\"'", methodParameters())
You can add the following live template:
for(int $INDEX$ = 0; $INDEX$ < $VAR$.size(); $INDEX$++){
$END$
}
Then go to right button "Edit variables" and put the following predefined methods in the expressions fields:
You can find all predefined methods in Jetbrains documentation

How to write to sqlite days of week?

I want to write to sqlite database checked day of weeks. For example, I have 7 checkBoxes, and I need to write checked items to database in one field. And when I will get this field from db, I need parse it.
How to do this better? Thanks
store it in integer type and parse with the method:
public int serializeDays(ArrayList<Boolean> isDayActive)
{
int result = 0;
for(int i = 0; i < 7; ++i)
result &= ((isDayActive.get(i) ? 1 : 0) << i);
return result;
}
when you read from db deserialize with the code:
public ArrayList<Boolean> deserializeDays(Integer fromBase)
{
ArrayList<Boolean> result = new ArrayList<Boolean>();
for(int i = 0; i < 7; ++i)
result.add((fromBase >> i) & 1 == 1 ? true : false);
return result;
}

Get the even and odd letters from a text

class oddevens{
public static void main(String[] args){
String A, Even, Odd;
int a,x,y;
x=0;
y=1;
A="sample text here";
a=A.length();
Even="";
Odd="";
for(int c=0;c==a;c++) {
if(c%2==0){
Even=Even+A.substring(x,y);
x=x+1;
y=y+1;
}else{
Odd=Odd+A.substring(x,y);
x=x+1;
y=y+1;
}
}
System.out.println("Even: "+Even+", Odd: "+Odd);
}
}
With this code, I try to divide String A by taking the 'even and odd' letters, so the output should look like this:
Even:sml ethr, Odd: apetx ee
But is not showing anything.
In your for loop, you have put c==a as the condition. Since a for loop runs for as long as that condition is met, your loop does not do anything (since c starts of as 0 and a starts of as the length of A.
It should be for(int c =0; c<a; c++)
A shorter solution to your problem would be something like this:
for(int c = 0; c < A.length(); c++){
if(c % 2 == 0{
Even += A.charAt(c);
}else{
Odd += A.charAt(c);
}
}
Your code will never run
for(int c=0;c==a;c++) {
.....
}
should be
for(int c=0;c < a;c++) {
.....
}
Anyway, you did not even tell us your problem.

String Multiline - Android

i got this issue and i don't know how to solve it. Here is the problem:
1 - i have a data in my database who i split into a strings[] and then i split this strings[] into another 2 strings[] (even and odd lines). Everything works fine but when i want to join all the lines into a single String i got a multi line string intead of a single line. Someone can help me?
data
abcdef//
123456//
ghijkl//
789012
code:
String text = "";
vec1 = data.split("//"); //split the data
int LE = 0;
for (int a = 0; a < vec1.length; a++) { //verify how many even and odds line the data have
if (a % 2 == 0) { //if 0, LE++
LE++;
}
}
resul1 = new String[LE];
int contA = 0, contB = 0;
for (int c = 0; c < resul1.length; c++) {
if (c % 2 != 0) {
text += " " + resul1[c].toLowerCase().replace("Á","a").replace("Ã","a").replace("ã","a").replace("â","a").replace("á","a").replace("é","e").replace("É","e")
.replace("ê","e").replace("í","i").replace("Í","i").replace("ó","o").replace("Ó","o").replace("õ","o").replace("Õ","o").replace("ô","o").replace("Ô", "o")
.replace("Ú","u").replace("ú","u").replace("ç","c").replace("_","").replace("<","").replace(">","");
contA++;
}
}
And the String looks like
abcdef
ghijkl
instead of
abcdefghijkl
You should use replaceAll() method.
text.replaceAll("\\r\\n|\\r|\\n", ""); // the method removes all newline characters

Android - How to set value of ArrayList to TextView

i have a problem here.
I've ArrayList from the result of my parser class. then i wanna put that value (value from ArrayList) to TextView.
here is the work i've done till now.
I create TextView on my main.xml
<TextView
android:id="#+id/deskripsi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
/>
and here at my onCreate Method, i initialized the Text View
desk = (TextView)findViewById(R.id.deskripsi);
and then i tried to parser the KML document from google map and at the Node Placemark i put its value to ArrayList, here my code
ArrayList<String> pathName = new ArrayList<String>();
Object[] objPlace;
//Parser Node Placemark
NodeList nlPlace = doc.getElementsByTagName("Placemark");
for(int p = 0; p < nlPlace.getLength(); p++){
Node rootPlace = nlPlace.item(p);
NodeList itemPlace = rootPlace.getChildNodes();
for(int y = 0; y < itemPlace.getLength(); y++){
Node placeStringNode = itemPlace.item(y);
NodeList place = placeStringNode.getChildNodes();
//valueName = nameList.item(0).getNodeValue().toString() + "+";
pathName.add(place.item(0).getNodeValue());
}
}
objPlace = pathName.toArray();
desk.setText("");
for (int j = 0; j < objPlace.length; j++){
desk.append("Deskripsi:\n" + objPlace[j].toString() + "\n");
}
but when itried to run its to my emulator and real device, i get an error. here's my LogCat
please help me, and sorry for my english >_<
You can do this instead; use pathName directly in the for loop...
desk.setText("");
for (int j = 0; j < pathName.size(); j++){
desk.append("Deskripsi:\n" + pathName.get(j) + "\n");
}
you can put the line
objPlace[] = new Object[pathName.size()]
before
objPlace = pathName.toArray();
and check output otherwise do this way
desk.setText("");
for (int j = 0; j < pathName.size(); j++){
desk.append("Deskripsi:\n" + pathName.get(j) + "\n");
}
You never initialize your array... objPlace[] is a null array.
You need to do something like:
objPlace[] = new Object[arraysizenumber]
Ii is caused by NullPointerException, that means some needs parameters and you have passed a null value to it.
Based on your code it might be around desk.setText("");. Try inserting a space or some value into it and run.
Thanks my fren. im still not really well on using Object[]. then i used this code for solving my problem
String strPlace[] = (String[])pathName.toArray(new String[pathName.size()]);
desk.setText("");
for (int j = 0; j < strPlace.length; j++){
desk.append("Deskripsi:\n" + strPlace[j] + "\n");
}
Thanks for userSeven7s, flameaddict and khan for trying to help me.
nice to know u all :)

Categories

Resources