How to make EditText clickable?












0















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










share|improve this question

























  • 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
















0















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










share|improve this question

























  • 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














0












0








0








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










share|improve this question
















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







android android-canvas






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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












3 Answers
3






active

oldest

votes


















0














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






share|improve this answer


























  • 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



















0














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.






share|improve this answer































    0














    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"






    share|improve this answer

























      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
      });


      }
      });














      draft saved

      draft discarded


















      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









      0














      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






      share|improve this answer


























      • 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
















      0














      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






      share|improve this answer


























      • 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














      0












      0








      0







      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






      share|improve this answer















      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







      share|improve this answer














      share|improve this answer



      share|improve this answer








      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



















      • 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













      0














      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.






      share|improve this answer




























        0














        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.






        share|improve this answer


























          0












          0








          0







          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.






          share|improve this answer













          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 6 '17 at 19:57









          Abhi MuktheeswararAbhi Muktheeswarar

          174110




          174110























              0














              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"






              share|improve this answer






























                0














                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"






                share|improve this answer




























                  0












                  0








                  0







                  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"






                  share|improve this answer















                  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"







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 15 '18 at 16:11









                  Agilanbu

                  1,2021420




                  1,2021420










                  answered Jan 6 '17 at 20:01









                  Waqas AhmedWaqas Ahmed

                  1159




                  1159






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      The Sandy Post

                      Danny Elfman

                      Pages that link to "Head v. Amoskeag Manufacturing Co."