Below is my code, i wanted to use the bing translate api to translate my 
strings.xml . I have a spinner in my code, when the user select the 
language in my spinner, i need to translate my strings.xml to my language, 
may i know how to do it?


package com.plantidentification;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Spinner;
import android.widget.Toast;
import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate;

/**
 * Created by YongLin on 1/23/2016.
 */
public class LanguageActivity extends Activity {
    Spinner spinnerctrl;
    String translatedText;


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        setTitle(R.string.title_activity_language);
        spinnerctrl = (Spinner) findViewById(R.id.spinner1);
        setContentView(R.layout.activity_language);

        spinnerctrl.setOnItemSelectedListener(new 
AdapterView.OnItemSelectedListener() {

            public void onItemSelected(AdapterView<?> parent, View view,
                                       int pos, long id) {

                if (pos == 1) {

                    Toast.makeText(parent.getContext(),
                            getResources().getString(R.string.YouselectEn), 
Toast.LENGTH_SHORT)
                            .show();

                } else if (pos == 2) {

                    Toast.makeText(parent.getContext(),
                            getResources().getString(R.string.YouselectZH), 
Toast.LENGTH_SHORT)
                            .show();
                    new MyAsyncTask() {
                        protected void onPostExecute(Boolean result) {
                           
translatedText=getResources().getString(R.string.HELLO);
                        }
                    }.execute();

                } else if (pos == 3) {

                    Toast.makeText(parent.getContext(),
                            getResources().getString(R.string.YouselectHI), 
Toast.LENGTH_SHORT)
                            .show();

                }
                else if (pos == 4) {

                    Toast.makeText(parent.getContext(),
                            getResources().getString(R.string.YouselectMs), 
Toast.LENGTH_SHORT)
                            .show();

                }


            }
                   public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub
                Toast.makeText(getApplicationContext(), "Nothing to select", 
Toast.LENGTH_LONG).show();
            }

            class MyAsyncTask extends AsyncTask<String, Integer, Boolean> {
                @Override
                protected Boolean doInBackground(String... arg0) {
                    Translate.setClientId("plantidentification");
                    
Translate.setClientSecret("lMFkUM+gG96NFrhhZV649Ix8NxR2SvqXJWpOTOgNq54=");
                    try {
                        translatedText = Translate.execute( 
getResources().getString(R.string.HELLO), Language.ENGLISH, 
Language.CHINESE_SIMPLIFIED);
                    } catch(Exception e) {
                        translatedText = e.toString();
                    }
                    return true;
                }
            }

        });
    }
}

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/a9249230-b520-4f19-bde0-5ddc9cf3817c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to