我有以下代碼。 當編輯文本拋出「找不到字符串」錯誤時,強制關閉。 我能做些什麼來防止它?例如使用Toast通知?發生錯誤時防止強制關閉
public void OnClImgBtSearch(View v)
{
ImageButton ImgBtSearch=(ImageButton) findViewById(R.id.ImgBtSearch);
EditText EditTextGhavaninShow=(EditText) findViewById(R.id.EditTextGhavaninShow);
EditText EditTextGhavaninSearch=(EditText) findViewById(R.id.EditTextGhavaninSearch);
String StrEditText =EditTextGhavaninSearch.getText().toString();
//(EditTextGhavaninShow.getText().toString().contains(StrEditText))
String s = EditTextGhavaninShow.getText().toString();
try{
if(EditTextGhavaninShow.getText().toString().contains(StrEditText));
{
int position = s.indexOf(StrEditText); // where C is your character to be searched
int Lastlen=s.lastIndexOf(StrEditText);
int FirstLen=s.indexOf(StrEditText);
EditTextGhavaninShow.setSelection(FirstLen,Lastlen);
}}
catch (TypeNotPresentException e) {
Toast.makeText(getApplicationContext(), "عبارت مورد نظر یافت نشد", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
可以顯示完整的堆棧跟蹤嗎? – Pooya
有沒有什麼方法可以選擇或突出顯示用戶在edittext中進行過濾的所有simlare單詞? –
我認爲這是一個不同的問題,最好是在SO – Pooya