How to check people input only japanese language - android

I want use only input japanese language but I don't know how to check between japanese input and anphabe input(sometime user could input a japanese character but missing something)
So what is my missing idea. I using a dictionary with two for loop but the performance so bad.
This is my code:
public List<String> getAnswer(String rawData) {
int length = rawData.length();
List<String> result = new ArrayList<String>();
for (int i = 0; i < length; i++) {
for (int j = 0; j < length - i; j++) {
String subString = rawData.substring(i, i + j);
if (mDict.containsKey(subString)) {
result.add(mDict.get(subString));
break;
}
}
}
return result;
}
And my dictionary:
<string-array name="dict_en">
<item>a</item>
<item>i</item>
<item>u</item>
<item>e</item>
<item>o</item>
</string-array>
<string-array name="dict_ja">
<item>あ</item>
<item>い</item>
<item>う</item>
<item>え</item>
<item>お</item>
</string-array>

Related

Problem with converted ASCII value in android

I have Multiple Hex Value.
String arr[] = {"4544582F3032313230362331383035350000000000000000000000000000",
"4544582F3032313230362331383035350000000000000000000000000000",
"300833B2DDD9014000000000",
"300833B2DDD9014000000000",
"300833B2DDD9014000000000000000000000000000000000000000000000",
"4544582F3034353532312335353531300000000000000000000000000000",
"4544582F3034353532312332353235380000000000000000000000000000",
"4544582F3034323736322332353235380000000000000000000000000000",
"4544582F3032313230362333373836390000000000000000000000000000",
"4544582F3032313230362332353235380000000000000000000000000000",
"4544582F3032313230362335353531300000000000000000000000000000"};
Conversion of HEX to ASCII code is:
for (int k = 0; k < arr.length; k++) {
StringBuilder output = new StringBuilder();
for (int i = 0; i < arr[k].length(); i += 2) {
String str = arr[k].substring(i, i + 2);
output.append((char) Integer.parseInt(str, 16));
}
textrfid.append(output + "\n");
code[k] = output.toString();
}
Log.e("Data", textrfid.getText().toString());
When convert Hex to ASCII value the result in Log is :
EDX/021206#18055����������������������������
EDX/021206#18055����������������������������
3²ÝÙ#��������
3²ÝÙ#��������
3²ÝÙ#��������������������������������������������
EDX/045521#55510����������������������������
EDX/045521#25258����������������������������
EDX/042762#25258����������������������������
EDX/021206#37869����������������������������
EDX/021206#25258����������������������������
EDX/021206#55510����������������������������
I have used replace method for remove (�) sign but it's still showing.
So Can you help me for removing the � symbol from value.

Android strings.xml character count

I'm struggling to find a way to count the amount of characters in my strings.xml.
If I select all it only tells me the total amount of ALL characters in the strings, but I want to know the real text characters without <string name="example"> and </string>
Try below one which is recommended
int stringLength=getString(R.String.example).trim().length();
or Try below method
private int getCount(String str) {
int counter = 0;
for (int i = 0; i < str.length(); i++) {
if (Character.isLetter(str.charAt(i)))
counter++;
}
System.out.println(counter + " letters.");
return counter;
}

Android shuffle Questions and Answers (string arrays)

I am making an app in which there are list of questions and respective answers.
Questions are in one string array, while answers are in another string array.
I have implemented the following in a wish to shuffle the questions. (Of course the answers need to be linked to that question, else meaningless)
Code:
selected_Q = new String[totalnoofQ];
selected_A = new String[totalnoofQ];
int[] random_code = new int[totalnoofQ];
for (int i = 0; i < totalnoofQ; i++)
{
random_code[i] = i;
}
Collections.shuffle(Arrays.asList(random_code));
for (int j = 0; j < totalnoofQ; j++)
{
int k = random_code[j];
selected_Q [j] = databank_Q [k];
selected_A[j] = databank_A [k];
}
The code reports no fatal error, but the selected_Q is still in sequential order. Why?
Could you please show me how can I amend the codes? Thanks!!!
You shuffle a list created using random_code, but random_code is not modified.
You need to create a temporary list based on random_code. Shuffle this list and then use it to fill the selected_X arrays.
Something like this should work :
int[] random_code = new int[totalnoofQ];
for (int i = 0 ; i < totalnoofQ ; i++) {
random_code[i] = i;
}
List<Integer> random_code_list = new ArrayList<Integer>(); // Create an arraylist (arraylist is used here because it has indexes)
for (int idx = 0 ; idx < random_code.length ; idx++) {
random_code_list.add(random_code[idx]); // Fill it
}
Collections.shuffle(random_code_list); // Shuffle it
for (int j = 0 ; j < totalnoofQ ; j++) {
int k = random_code_list.get(j); // Get the value
selected_Q[j] = databank_Q[k];
selected_A[j] = databank_A[k];
}

splitting larger array in to smaller array

In my app I have array size 400 elements. My task is Those elements are send to webservice for inserting.But it is not supported.So split the array into pieces and send to webservice.How is it
Something like this, perhaps?
String[] stringArray = new String[400];
//lets assume that the array has objects in it.
int index = 0;
for(int i = 0; i < stringArray.length; i++) {
String[] temp = new String[20];
for(int x = 0; x < 20) {
if(stringArray[index] != null) temp[x] = stringArray[index];
index++;
}
//The temp array is filled with objects from the other array, so send it to the webservice.
sendArrayToWebService(temp);
}

android JSONArray length

i have an array from a json feed i know that in the jArray there is one league but i need to work out the count of that array incase a second is added to the feed at a later date. at the moment log cat isn't logging out "teamFeedStructure" does anyone know what I'm doing wrong or know how to correctly turn the length of an array into a string that i can use in an intent?
heres the code
JSONObject obj = new JSONObject(json);
JSONObject objData = obj.getJSONObject("data");
JSONArray jArray = objData.getJSONArray("structure");
//String leagues = jArray.toString();
//Log.v("myapp", "structure" + leagues);
for (int i=0; i < jArray.length(); i++) {
JSONObject oneObject = jArray.getJSONObject(i);
leaguecountArray = oneObject.getJSONArray("league_id");
for (int l=0; l < leaguecountArray.length(); l++) {
if (leaguecountArray.length() == 1) {
teamFeedStructure = "One";
}
if (leaguecountArray.length() == 2) {
teamFeedStructure = "Two";
}
Log.v("myapp", teamFeedStructure);
}
}
Why do you need to iterate here:
for (int l=0; l < leaguecountArray.length(); l++)
{
if (leaguecountArray.length() == 1){
teamFeedStructure = "One";
}
if (leaguecountArray.length() == 2){
teamFeedStructure = "Two";
}
Log.v("myapp", teamFeedStructure);
}
Nevermind how many passes you do the result will still be the same.
Also you can use not English words, but String holding the number you need. Do like that:
teamFeedStructure = String.valueOf(leaguecountArray.length());
Then the value will become "2" for example. In your other activity you can parse it again to integer like that: int number = Integer.parseInt(teamFeedStructure);
Add the following line
teamFeedStructure = "greater two";
before
if (leaguecountArray.length() == 1){
If you get greater two message, means your array length more than two.
Thanks for your help everyone i discovered that i had gone a step too far into the feed which is why i was not getting anything in Logcat. now it's counting fine.

Categories

Resources