Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How make Spelling Checker function in android.

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 147
    Comment on it

    In the below code I have used SpellCheckerListener interface and ovrride its method. Here I have created SpellCheckerListener class to check the spelling errors. See the below code it will clearly described how to make Spelling Checker function.

    public class MainActivity extends Activity implements SpellCheckerSessionListener  {
       Button b1;
       TextView tv1;
       EditText ed1;
       private SpellCheckerSession mScs;
    
       @Override
       protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
    
          b1=(Button)findViewById(R.id.button);
          tv1=(TextView)findViewById(R.id.textView3);
    
          ed1=(EditText)findViewById(R.id.editText);
          b1.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                Toast.makeText(getApplicationContext(), ed1.getText().toString(),Toast.LENGTH_SHORT).show();
                mScs.getSuggestions(new TextInfo(ed1.getText().toString()), 3);
             }
          });
       }
    
       public void onResume() {
          super.onResume();
          final TextServicesManager tsm = (TextServicesManager) getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE);
          mScs = tsm.newSpellCheckerSession(null, null, this, true);
       }
    
       public void onPause() {
          super.onPause();
          if (mScs != null) {
             mScs.close();
          }
       }
    
       public void onGetSuggestions(final SuggestionsInfo[] arg0) {
          final StringBuilder sb = new StringBuilder();
    
          for (int i = 0; i < arg0.length; ++i) {
             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() {
             public void run() {
                tv1.append(sb.toString());
             }
          });
       }
    
       @Override
       public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] arg0) {
       }
    
       @Override
       public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.menu_main, menu);
          return true;
       }
    
       @Override
       public boolean onOptionsItemSelected(MenuItem item) {
    
          int id = item.getItemId();
    
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
             return true;
          }
          return super.onOptionsItemSelected(item);
       }
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: