Reputation: 1249
Code
edtAddress = (EditText) findViewById(R.id.edtAddress);
edtAddress.setTag(edtAddress.getKeyListener());
edtAddress.setKeyListener(null);
imgEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
edtAddress.setKeyListener((KeyListener) edtAddress.getTag());
}
});
HI, i have a problem while open app then the edit text is not editable, but when click on edit button then that edit text is editable.
i have done this code but, problem is that when i click on edit button then edit text(edtAddress) is editable but, when type any character then edit text is not getting input character and app is crash.
what is the problem there, suggest me
ERROR
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.hit.fyl_owner, PID: 3128
java.lang.IndexOutOfBoundsException
at android.graphics.Canvas.drawText(Canvas.java:1696)
at android.text.Layout.drawText(Layout.java:410)
at android.widget.Editor.drawHardwareAccelerated(Editor.java:1585)
at android.widget.Editor.onDraw(Editor.java:1507)
at android.widget.TextView.onDraw(TextView.java:5715)
at android.view.View.draw(View.java:16178)
at android.view.View.updateDisplayListIfDirty(View.java:15174)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
at android.view.View.updateDisplayListIfDirty(View.java:15134)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
at android.view.View.updateDisplayListIfDirty(View.java:15134)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
at android.view.View.updateDisplayListIfDirty(View.java:15134)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
at android.view.View.updateDisplayListIfDirty(View.java:15134)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
at android.view.View.updateDisplayListIfDirty(View.java:15134)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
at android.view.View.updateDisplayListIfDirty(View.java:15134)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
at android.view.View.updateDisplayListIfDirty(View.java:15134)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:281)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:287)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:322)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2615)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2434)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2067)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:606)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Upvotes: 1
Views: 1317
Reputation: 652
I added two attributes
android:singleLine="true"
android:imeOptions="actionDone"
and everything started working as normal. Well, I still do not understand the cause and may dig into it further but hope this will help for now.
Upvotes: 0
Reputation: 26
you can set edittext disable.
edtOrganization.setFocusable(false);
now you can set edittext enable.
edtFirst.setFocusable(true);
edtFirst.setFocusableInTouchMode(true);
Upvotes: 1
Reputation: 11
Add this to your EditText xml file:
<EditText ...
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false">
</EditText>
Upvotes: 0
Reputation: 1819
try using this code,
edtAddress = (EditText) findViewById(R.id.edtAddress);
edtAddress.setEnabled(false);
imgEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{
edtAddress.setEnabled(true);
edtAddress.requestFocus();
}
});
Upvotes: 1
Reputation: 531
You can add "requestFocus", which focuses the EditText
<EditText...>
<requestFocus />
</EditText>
Upvotes: 0