我有微調和編輯文本,我想如果微調選擇可以在edittext中setfocus。我已經嘗試過,但不能工作,如何解決這個問題?如何將焦點集中在微調器上?
這是我的代碼:
edkontak1.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId== EditorInfo.IME_ACTION_NEXT) {
sembunyikanKeyboard();
v.clearFocus();
spinnerkontak1.requestFocus();
spinnerkontak1.performClick();
}
return true;
}
});
spinnerkontak1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String jeniskontak1 = spinnerkontak1.getSelectedItem().toString();
if(jeniskontak1.equals("--")){
edkontak1.setText("");
edkontak1.setEnabled(false);
tkontak2.setVisibility(View.GONE);
tkontak3.setVisibility(View.GONE);
tkontak4.setVisibility(View.GONE);
tkontak5.setVisibility(View.GONE);
}
else{
edkontak1.setEnabled(true);
tkontak2.setVisibility(View.VISIBLE);
spinnerkontak1.setFocusable(true);
spinnerkontak1.setFocusableInTouchMode(true);
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
private void sembunyikanKeyboard() {
InputMethodManager inputmanaget = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputmanaget.hideSoftInputFromInputMethod(this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
在此先感謝。
上微調 –
添加requestFocus()方法謝謝主席先生,不過這僅僅是我的錯誤。我設置了微調器請求焦點和edittext setFocusable = true –