How do I focus on the counter?
I have a spinner and an edittext and I want if the spinner is selected the focus can be set in the edittext. I'm already trying but not going to work, how do I fix this?
This is my code:
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);
}
Thanks in advance.
+3
source to share