I want to Edit Text but only on onClick event and soon as it finishes the cursor visibility should be false again like before. Only onClick event would show cursor and editing enable as soon as done typing and press keyboard action button it should make the cursor visibility false again
Here is Xml part
<EditText
android:id="@+id/pname"
android:textStyle="bold"
android:layout_toRightOf="@+id/profileimg"
android:inputType="none"
android:layout_marginBottom="15dp"
android:layout_alignParentBottom="true"
android:layout_marginLeft="15dp"
android:textAllCaps="true"
android:cursorVisible="false"
android:background="@android:color/transparent"
android:hint="@string/nickname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLength="10"
android:clickable="true"
android:onClick="onClick"/>
This is Coding part:
pname = (EditText) findViewById(R.id.pname);
pname.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pname.setInputType(0x0000006);
pname.setCursorVisible(true);
}
});
/*pname.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
pname.setCursorVisible(false);
} else {
pname.setCursorVisible(false);
}
}
});
*/
pname.setOnEditorActionListener(new EditText.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER || actionId ==EditorInfo.IME_ACTION_DONE) {
if (!event.isShiftPressed()) {
pname.setCursorVisible(false);
return true; // consume.
}
}
return false;
}
});
Problem/Error: It seems as soon as I am done typing and press keyboard action done key my activity stops working unfortunately
Exception:
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.KeyEvent.getKeyCode()' on a null object reference at packagename.MainActivity$2.onEditorAction(MainActivity.java:69) line no 69