拼写检查器在Android中显示错误?
我正在尝试使用EditText运行Android拼写检查器,但它没有运行,并显示一些错误,如下所示: 我的活动如下:拼写检查器在Android中显示错误?,android,Android,我正在尝试使用EditText运行Android拼写检查器,但它没有运行,并显示一些错误,如下所示: 我的活动如下: import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.View; import android.view.textservice.SentenceSuggestionsInfo; import android.view.t
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.textservice.SentenceSuggestionsInfo;
import android.view.textservice.SpellCheckerSession;
import android.view.textservice.SpellCheckerSession.SpellCheckerSessionListener;
import android.view.textservice.SuggestionsInfo;
import android.view.textservice.TextInfo;
import android.view.textservice.TextServicesManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class HelloSpellCheckerActivity extends Activity implements SpellCheckerSessionListener {
private static final int NOT_A_LENGTH = -1;
private TextView mMainView;
private SpellCheckerSession mScs;
private EditText editText1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mMainView = (TextView)findViewById(R.id.main);
editText1 = (EditText)findViewById(R.id.editText1);
}
@Override
public void onResume() {
super.onResume();
final TextServicesManager tsm = (TextServicesManager) getSystemService(
Context.TEXT_SERVICES_MANAGER_SERVICE);
mScs = tsm.newSpellCheckerSession(null, null, this, true);
}
@Override
public void onPause() {
super.onPause();
if (mScs != null) {
mScs.close();
}
}
public void go(View view){
Toast.makeText(getApplicationContext(), editText1.getText().toString(),
Toast.LENGTH_SHORT).show();
mScs.getSuggestions(new TextInfo(editText1.getText().toString()), 3);
}
@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() {
public void run() {
mMainView.append(sb.toString());
}
});
}
@Override
public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] arg0) {
// TODO Auto-generated method stub
}
}
我正在上传错误的图像。请查看并让我知道发生此错误的原因:
您的清单的版本为8,这将不起作用
您必须将清单文件中的minSdkVersion更改为14
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
正如在API级别14中添加的,您的项目显示错误
希望这能有所帮助。你清理并构建了吗?我没有收到任何这样的问题。我收到这个问题,我清理建设以及,但图像错误显示。奇怪。重新启动eclipse。这应该可以正常工作。此导入未被识别导入android.view.textservice.SentenceSuggestionsInfo;对于我来说,导入android.view.textservice.SentenceSuggestionsInfo;工作正常。我刚刚编写了ImplementSpellCheckerSessionListener,作为建议导入,并单击了override方法,它的工作非常好。没有编译错误。