tags:

views:

73

answers:

1

hi i am new to android.what i did is implementing the search with the edit text for that i am writing the code as fallows.

((EditText)findViewById(R.id.EditText01)).setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if(event.getAction() == KeyEvent.ACTION_UP){

            String enteredText = ((EditText)findViewById(R.id.EditText01)).getText().toString();

            if(enteredText.length() > 0 ) {
            String str1 =""+ enteredText.charAt(0);

            str1 = str1.toUpperCase();
            String str2 =""+ enteredText.substring(1);
            str2 = str2.toLowerCase();
            enteredText = str1 + str2;

            }
             id=0;
             Iterator<String> strIt = strList.iterator();
             Log.v("", "Total items in the list****"+strList);
            ((LinearLayout)findViewById(R.id.LinearLayout02)).removeAllViewsInLayout();
            if(strIt.next().startsWith(enteredText))
            {
                Log.v("", "hi u r enterd letter is there in list");
            }
            else
            {
                ((LinearLayout)findViewById(R.id.LinearLayout02)).removeAllViewsInLayout();
                Toast.makeText(MyShoppingList.this, "There is no item In the List Start with Letter "+enteredText+" Click Add Item to Add New Item" ,06 ).show();
                Log.v("", " u enterd letter is no there in list"+enteredText);
                additem();

            }

            count = 0;
            while(strIt.hasNext()){
                String str = strIt.next();

                if(str.startsWith(enteredText)){

                    //count++;
                matchingLetters(str);

            }


            }

            }

                    return false;       }

        });

it works fine,but i am getting problem when key pad of device in active.it doee implement when keypad in active while minimizing the key pad code then only it runs. what's problem i can n't understand pls help me.post some code or link.Thank u in advance.

+1  A: 

Hi Mahesh, Please note: onKey() returns a boolean to indicate whether you have consumed the event and it should not be carried further. That is, return true to indicate that you have handled the event and it should stop here; return false if you have not handled it and/or the event should continue to any other on-key listeners. http://developer.android.com/reference/android/view/View.OnKeyListener.html#onKey(android.view.View, int, android.view.KeyEvent)

So in my opinion you must return true & then post back the result to StackOverflow.

100rabh