How to make EditText clickable?
Sorry if it is sort of duplicate question with this one, I have tried the solutions provided and on some other posts too but none of them are working for me.
I have drawn the EditText but it is not clickable (no keyboard appeared after touch)
public class GamePanel extends SurfaceView implements SurfaceHolder.Callback{
private LinearLayout lL;
private EditText editText;
@Override
public void surfaceCreated(SurfaceHolder holder){
lL = new LinearLayout(getContext());
editText = new EditText(getContext());
editText.setFocusableInTouchMode(true);
editText.setClickable(true);
editText.requestFocus();
editText.setText("Hello World");
editText.setVisibility(View.VISIBLE);
lL.addView(editText);
lL.setDrawingCacheEnabled(true);
lL.measure(canvas.getWidth(), canvas.getHeight());
lL.layout(0, 0, canvas.getWidth(), canvas.getHeight());
lL.bringChildToFront(editTextView);
}
@Override
public void draw(Canvas canvas){
canvas.drawBitmap(lL.getDrawingCache(),50,50,null);
}
}
I have also tried this from the solution I saw: (using xml to create the EditText)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
Change EditText to this and remove canvas.drawBitmap():
EditText editText = (EditText)findViewById(R.id.editText1);
but the app always force closed when I did this.
Main problem is how to make EditText clickable and show the soft keyboard like when you just put it from xml without drawing it on canvas at all
|
show 2 more comments
Sorry if it is sort of duplicate question with this one, I have tried the solutions provided and on some other posts too but none of them are working for me.
I have drawn the EditText but it is not clickable (no keyboard appeared after touch)
public class GamePanel extends SurfaceView implements SurfaceHolder.Callback{
private LinearLayout lL;
private EditText editText;
@Override
public void surfaceCreated(SurfaceHolder holder){
lL = new LinearLayout(getContext());
editText = new EditText(getContext());
editText.setFocusableInTouchMode(true);
editText.setClickable(true);
editText.requestFocus();
editText.setText("Hello World");
editText.setVisibility(View.VISIBLE);
lL.addView(editText);
lL.setDrawingCacheEnabled(true);
lL.measure(canvas.getWidth(), canvas.getHeight());
lL.layout(0, 0, canvas.getWidth(), canvas.getHeight());
lL.bringChildToFront(editTextView);
}
@Override
public void draw(Canvas canvas){
canvas.drawBitmap(lL.getDrawingCache(),50,50,null);
}
}
I have also tried this from the solution I saw: (using xml to create the EditText)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
Change EditText to this and remove canvas.drawBitmap():
EditText editText = (EditText)findViewById(R.id.editText1);
but the app always force closed when I did this.
Main problem is how to make EditText clickable and show the soft keyboard like when you just put it from xml without drawing it on canvas at all
Do not instanciate the views in your on draw method!!! The on draw is always called when the view or a part of the view is invalidated. create your layout in the constructor of your custom view and add it.
– Fabian
Jun 25 '15 at 15:18
you might wann use this editText2= (EditText) findViewById(R.id.editText2); firstEText.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { //todo: something } } });
– ASP
Jun 25 '15 at 15:19
Do not initialize view in draw method and could you post your logcat stack trace?
– RajSharma
Jun 25 '15 at 15:24
Fabian @CodeProcessor thanks. edited. and my logcat stack trace only consists of SurfaceView returned and locking canvas.
– Rawr
Jun 25 '15 at 15:31
@ASP I've tried that and write System.out.println("ABC"); replacing //todo but nothing printed after I touched the EditText
– Rawr
Jun 25 '15 at 15:33
|
show 2 more comments
Sorry if it is sort of duplicate question with this one, I have tried the solutions provided and on some other posts too but none of them are working for me.
I have drawn the EditText but it is not clickable (no keyboard appeared after touch)
public class GamePanel extends SurfaceView implements SurfaceHolder.Callback{
private LinearLayout lL;
private EditText editText;
@Override
public void surfaceCreated(SurfaceHolder holder){
lL = new LinearLayout(getContext());
editText = new EditText(getContext());
editText.setFocusableInTouchMode(true);
editText.setClickable(true);
editText.requestFocus();
editText.setText("Hello World");
editText.setVisibility(View.VISIBLE);
lL.addView(editText);
lL.setDrawingCacheEnabled(true);
lL.measure(canvas.getWidth(), canvas.getHeight());
lL.layout(0, 0, canvas.getWidth(), canvas.getHeight());
lL.bringChildToFront(editTextView);
}
@Override
public void draw(Canvas canvas){
canvas.drawBitmap(lL.getDrawingCache(),50,50,null);
}
}
I have also tried this from the solution I saw: (using xml to create the EditText)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
Change EditText to this and remove canvas.drawBitmap():
EditText editText = (EditText)findViewById(R.id.editText1);
but the app always force closed when I did this.
Main problem is how to make EditText clickable and show the soft keyboard like when you just put it from xml without drawing it on canvas at all
Sorry if it is sort of duplicate question with this one, I have tried the solutions provided and on some other posts too but none of them are working for me.
I have drawn the EditText but it is not clickable (no keyboard appeared after touch)
public class GamePanel extends SurfaceView implements SurfaceHolder.Callback{
private LinearLayout lL;
private EditText editText;
@Override
public void surfaceCreated(SurfaceHolder holder){
lL = new LinearLayout(getContext());
editText = new EditText(getContext());
editText.setFocusableInTouchMode(true);
editText.setClickable(true);
editText.requestFocus();
editText.setText("Hello World");
editText.setVisibility(View.VISIBLE);
lL.addView(editText);
lL.setDrawingCacheEnabled(true);
lL.measure(canvas.getWidth(), canvas.getHeight());
lL.layout(0, 0, canvas.getWidth(), canvas.getHeight());
lL.bringChildToFront(editTextView);
}
@Override
public void draw(Canvas canvas){
canvas.drawBitmap(lL.getDrawingCache(),50,50,null);
}
}
I have also tried this from the solution I saw: (using xml to create the EditText)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
Change EditText to this and remove canvas.drawBitmap():
EditText editText = (EditText)findViewById(R.id.editText1);
but the app always force closed when I did this.
Main problem is how to make EditText clickable and show the soft keyboard like when you just put it from xml without drawing it on canvas at all
edited May 23 '17 at 12:09
Community♦
11
11
asked Jun 25 '15 at 15:11
RawrRawr
31210
31210
Do not instanciate the views in your on draw method!!! The on draw is always called when the view or a part of the view is invalidated. create your layout in the constructor of your custom view and add it.
– Fabian
Jun 25 '15 at 15:18
you might wann use this editText2= (EditText) findViewById(R.id.editText2); firstEText.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { //todo: something } } });
– ASP
Jun 25 '15 at 15:19
Do not initialize view in draw method and could you post your logcat stack trace?
– RajSharma
Jun 25 '15 at 15:24
Fabian @CodeProcessor thanks. edited. and my logcat stack trace only consists of SurfaceView returned and locking canvas.
– Rawr
Jun 25 '15 at 15:31
@ASP I've tried that and write System.out.println("ABC"); replacing //todo but nothing printed after I touched the EditText
– Rawr
Jun 25 '15 at 15:33
|
show 2 more comments
Do not instanciate the views in your on draw method!!! The on draw is always called when the view or a part of the view is invalidated. create your layout in the constructor of your custom view and add it.
– Fabian
Jun 25 '15 at 15:18
you might wann use this editText2= (EditText) findViewById(R.id.editText2); firstEText.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { //todo: something } } });
– ASP
Jun 25 '15 at 15:19
Do not initialize view in draw method and could you post your logcat stack trace?
– RajSharma
Jun 25 '15 at 15:24
Fabian @CodeProcessor thanks. edited. and my logcat stack trace only consists of SurfaceView returned and locking canvas.
– Rawr
Jun 25 '15 at 15:31
@ASP I've tried that and write System.out.println("ABC"); replacing //todo but nothing printed after I touched the EditText
– Rawr
Jun 25 '15 at 15:33
Do not instanciate the views in your on draw method!!! The on draw is always called when the view or a part of the view is invalidated. create your layout in the constructor of your custom view and add it.
– Fabian
Jun 25 '15 at 15:18
Do not instanciate the views in your on draw method!!! The on draw is always called when the view or a part of the view is invalidated. create your layout in the constructor of your custom view and add it.
– Fabian
Jun 25 '15 at 15:18
you might wann use this editText2= (EditText) findViewById(R.id.editText2); firstEText.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { //todo: something } } });
– ASP
Jun 25 '15 at 15:19
you might wann use this editText2= (EditText) findViewById(R.id.editText2); firstEText.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { //todo: something } } });
– ASP
Jun 25 '15 at 15:19
Do not initialize view in draw method and could you post your logcat stack trace?
– RajSharma
Jun 25 '15 at 15:24
Do not initialize view in draw method and could you post your logcat stack trace?
– RajSharma
Jun 25 '15 at 15:24
Fabian @CodeProcessor thanks. edited. and my logcat stack trace only consists of SurfaceView returned and locking canvas.
– Rawr
Jun 25 '15 at 15:31
Fabian @CodeProcessor thanks. edited. and my logcat stack trace only consists of SurfaceView returned and locking canvas.
– Rawr
Jun 25 '15 at 15:31
@ASP I've tried that and write System.out.println("ABC"); replacing //todo but nothing printed after I touched the EditText
– Rawr
Jun 25 '15 at 15:33
@ASP I've tried that and write System.out.println("ABC"); replacing //todo but nothing printed after I touched the EditText
– Rawr
Jun 25 '15 at 15:33
|
show 2 more comments
3 Answers
3
active
oldest
votes
You can set property of Layout like android:descendantFocusability="beforeDescendants" and android:focusableInTouchMode="enter code here"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:descendantFocusability="beforeDescendants"
android:layout_height="match_parent">
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
May this one helpful ;)
How to make EditText not focused when creating Activity
umm can you please explain what's the purpose of that? I set it just now and nothing changed.
– Rawr
Jun 25 '15 at 15:43
Edit Text not Taking Focus
– Anil Meenugu
Jun 25 '15 at 15:55
I've typed android:descendantFocusability="beforeDescendants" and android:focusableInTouchMode="true" and tried "false" too but none of them are making any changes. I have no idea why
– Rawr
Jun 25 '15 at 16:05
add a comment |
By default, if you click edittext, keyboard will be visible unless you did something to change the behaviour. No need to set clickable,focusable in xml layout. Just create a edittext & use it.
add a comment |
If you want to use edit text as to open something like date picker dialog you can use set focusable to flase. Hence clicking on edit text will open dialog etc.
Example : android:focusable="flase"
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f31054217%2fhow-to-make-edittext-clickable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can set property of Layout like android:descendantFocusability="beforeDescendants" and android:focusableInTouchMode="enter code here"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:descendantFocusability="beforeDescendants"
android:layout_height="match_parent">
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
May this one helpful ;)
How to make EditText not focused when creating Activity
umm can you please explain what's the purpose of that? I set it just now and nothing changed.
– Rawr
Jun 25 '15 at 15:43
Edit Text not Taking Focus
– Anil Meenugu
Jun 25 '15 at 15:55
I've typed android:descendantFocusability="beforeDescendants" and android:focusableInTouchMode="true" and tried "false" too but none of them are making any changes. I have no idea why
– Rawr
Jun 25 '15 at 16:05
add a comment |
You can set property of Layout like android:descendantFocusability="beforeDescendants" and android:focusableInTouchMode="enter code here"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:descendantFocusability="beforeDescendants"
android:layout_height="match_parent">
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
May this one helpful ;)
How to make EditText not focused when creating Activity
umm can you please explain what's the purpose of that? I set it just now and nothing changed.
– Rawr
Jun 25 '15 at 15:43
Edit Text not Taking Focus
– Anil Meenugu
Jun 25 '15 at 15:55
I've typed android:descendantFocusability="beforeDescendants" and android:focusableInTouchMode="true" and tried "false" too but none of them are making any changes. I have no idea why
– Rawr
Jun 25 '15 at 16:05
add a comment |
You can set property of Layout like android:descendantFocusability="beforeDescendants" and android:focusableInTouchMode="enter code here"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:descendantFocusability="beforeDescendants"
android:layout_height="match_parent">
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
May this one helpful ;)
How to make EditText not focused when creating Activity
You can set property of Layout like android:descendantFocusability="beforeDescendants" and android:focusableInTouchMode="enter code here"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:descendantFocusability="beforeDescendants"
android:layout_height="match_parent">
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
May this one helpful ;)
How to make EditText not focused when creating Activity
edited May 23 '17 at 12:09
Community♦
11
11
answered Jun 25 '15 at 15:36
Anil MeenuguAnil Meenugu
1,245715
1,245715
umm can you please explain what's the purpose of that? I set it just now and nothing changed.
– Rawr
Jun 25 '15 at 15:43
Edit Text not Taking Focus
– Anil Meenugu
Jun 25 '15 at 15:55
I've typed android:descendantFocusability="beforeDescendants" and android:focusableInTouchMode="true" and tried "false" too but none of them are making any changes. I have no idea why
– Rawr
Jun 25 '15 at 16:05
add a comment |
umm can you please explain what's the purpose of that? I set it just now and nothing changed.
– Rawr
Jun 25 '15 at 15:43
Edit Text not Taking Focus
– Anil Meenugu
Jun 25 '15 at 15:55
I've typed android:descendantFocusability="beforeDescendants" and android:focusableInTouchMode="true" and tried "false" too but none of them are making any changes. I have no idea why
– Rawr
Jun 25 '15 at 16:05
umm can you please explain what's the purpose of that? I set it just now and nothing changed.
– Rawr
Jun 25 '15 at 15:43
umm can you please explain what's the purpose of that? I set it just now and nothing changed.
– Rawr
Jun 25 '15 at 15:43
Edit Text not Taking Focus
– Anil Meenugu
Jun 25 '15 at 15:55
Edit Text not Taking Focus
– Anil Meenugu
Jun 25 '15 at 15:55
I've typed android:descendantFocusability="beforeDescendants" and android:focusableInTouchMode="true" and tried "false" too but none of them are making any changes. I have no idea why
– Rawr
Jun 25 '15 at 16:05
I've typed android:descendantFocusability="beforeDescendants" and android:focusableInTouchMode="true" and tried "false" too but none of them are making any changes. I have no idea why
– Rawr
Jun 25 '15 at 16:05
add a comment |
By default, if you click edittext, keyboard will be visible unless you did something to change the behaviour. No need to set clickable,focusable in xml layout. Just create a edittext & use it.
add a comment |
By default, if you click edittext, keyboard will be visible unless you did something to change the behaviour. No need to set clickable,focusable in xml layout. Just create a edittext & use it.
add a comment |
By default, if you click edittext, keyboard will be visible unless you did something to change the behaviour. No need to set clickable,focusable in xml layout. Just create a edittext & use it.
By default, if you click edittext, keyboard will be visible unless you did something to change the behaviour. No need to set clickable,focusable in xml layout. Just create a edittext & use it.
answered Jan 6 '17 at 19:57
Abhi MuktheeswararAbhi Muktheeswarar
174110
174110
add a comment |
add a comment |
If you want to use edit text as to open something like date picker dialog you can use set focusable to flase. Hence clicking on edit text will open dialog etc.
Example : android:focusable="flase"
add a comment |
If you want to use edit text as to open something like date picker dialog you can use set focusable to flase. Hence clicking on edit text will open dialog etc.
Example : android:focusable="flase"
add a comment |
If you want to use edit text as to open something like date picker dialog you can use set focusable to flase. Hence clicking on edit text will open dialog etc.
Example : android:focusable="flase"
If you want to use edit text as to open something like date picker dialog you can use set focusable to flase. Hence clicking on edit text will open dialog etc.
Example : android:focusable="flase"
edited Nov 15 '18 at 16:11
Agilanbu
1,2021420
1,2021420
answered Jan 6 '17 at 20:01
Waqas AhmedWaqas Ahmed
1159
1159
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f31054217%2fhow-to-make-edittext-clickable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Do not instanciate the views in your on draw method!!! The on draw is always called when the view or a part of the view is invalidated. create your layout in the constructor of your custom view and add it.
– Fabian
Jun 25 '15 at 15:18
you might wann use this editText2= (EditText) findViewById(R.id.editText2); firstEText.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { //todo: something } } });
– ASP
Jun 25 '15 at 15:19
Do not initialize view in draw method and could you post your logcat stack trace?
– RajSharma
Jun 25 '15 at 15:24
Fabian @CodeProcessor thanks. edited. and my logcat stack trace only consists of SurfaceView returned and locking canvas.
– Rawr
Jun 25 '15 at 15:31
@ASP I've tried that and write System.out.println("ABC"); replacing //todo but nothing printed after I touched the EditText
– Rawr
Jun 25 '15 at 15:33