4

I have a listview , and edittext on top of it. The edittext is searching data from listview. Listview is populated from string-array. The edittext search function is working fine, but onclick is not working. It should go to another activity passing some intents. How can I do that? I am using this method.IS it correct ? How to pass the intents?

  editText.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {


        }
    });

Thanks

sarah
  • 265
  • 1
  • 3
  • 13
  • What do you mean by `onClick` not working? Please elaborate. – Arnab Chakraborty Sep 05 '11 at 15:06
  • Why are you trying to assign an onClick event that would open another activity to an EditText??? Especially since it sounds like the EditText would be used for search the ListView. This sounds like bad UI design. – SBerg413 Sep 05 '11 at 15:21
  • @SBerg413 what do you suggest then? An autocomplete textview in stead of edit text?? – sarah Sep 05 '11 at 20:41
  • See also https://stackoverflow.com/questions/2359176/android-edittext-onclicklistener. – CoolMind Oct 07 '19 at 09:54

3 Answers3

15

If you set the android:focusableInTouchMode property of the EditText view to "false" in the layout xml file, the onClickListener should behave as expected.

Andrej Cvoro
  • 371
  • 1
  • 5
2

Say the name of your activities are FromActivity and ToActivity, then you should write something like this:

editText.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
       Intent i = new Intent(FromActivity.this, ToActivity.class);
       startActivity(i);
    }
});

That should load the desired activity.

Edit: Although you should really reconsider invoking the Activity on a button click maybe. Invoking it in the onClick of the EditText is not something a user would expect.

Arnab Chakraborty
  • 7,442
  • 9
  • 46
  • 69
0

If your onClickListener is not called, ensure that your EditText is actually clickable. You can do that either by a XML configuration or programmatically.

Then, in your listener, do exactly as Aki explained in another answer of this page.

Shlublu
  • 10,917
  • 4
  • 51
  • 70