내가 편집 텍스트에 단어를 넣었을 때 숨겨진 버튼을 표시하고 싶다. 이 라인을 제외하고설정 버튼 안드로이드의 텍스트 워처에서 보이거나 보이지 않는다.
final EditText txtSearch = (EditText)findViewById(R.id.txtSearch);
txtSearch.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
((Button)findViewById(R.id.btnClear)).setVisibility(View.VISIBLE);
CategoryCustomAdapter adapter2 =
new CategoryCustomAdapter(showCategoryListActivity.this,
DatabaseHelper.getCategories(
showCategoryListActivity.this,s.toString()));
((ListView)findViewById(R.id.lstCategorylist)).setAdapter(adapter2);
}
@Override
public void afterTextChanged(Editable s) {
}
});
모든 일이 잘 작동 :이 TextWatcher에서 내 코드
((Button)findViewById(R.id.btnClear)).setVisibility(View.VISIBLE);
입니다 : 메신저는 이미이 방법을 시도
((Button)findViewById(R.id.btnClear)).setVisibility(View.VISIBLE);
을 난 당신이 도움이 될 수 있습니다 확신 해요 나 밖으로. ps : API 19 Nexus 4 android 4.4.2
당신이 당신의 버튼을하기 전에 할당 할 수 있습니다? 개인적으로 나는 afterTextChanged에 코드를 넣을 것이다. 그런 다음 btnClear.setvisibility (count> 0? VISIBLE : GONE);을 넣을 수 있습니다. – JCDecary
그게 해결책이 아닌가 걱정됩니다. 하지만 당신이 말한 모든 일을 했는데도 아무 일도 없었습니다. (처음에는 강제로 닫습니다) –
강제 종료 할 경우 여기에 logcat 로그를 게시 할 수 있습니까? 어떻게 그 라인을 제외한 모든 것이 잘 작동한다고 말할 수 있습니까? 내가 생각하는 유일한 이유는 "R.id.btnClear"이름이 잘못되었다는 것입니다. –