Search code examples
androidmenusearchview

How clean text in search view when click outside


I have a search view in my app. Also have menu search. How do I clean text from search view when I clik outside (for example somewhere on empty place)? I was looking for an answer to the question, but I didn't find appropriate.

 @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.searchable_dictionary, menu);

        MenuItem item = menu.findItem(R.id.search);

        SearchView searchView = (SearchView)MenuItemCompat.getActionView(item);

        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
        searchView.setSearchableInfo(info); 




        return true;


    }




    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.search:
                onSearchRequested();
                return false;

            case R.id.about:
                startActivity(new Intent(this, About.class));
                return true;


            default:
                return false;

        }

Solution

  • SQLite has limited ALTER TABLE support that you can use to add a column to the end of a table or to change the name of a table. If you want to make more complex changes in the structure of a table, you will have to recreate the table. You can save existing data to a temporary table, drop the old table, create the new table, then copy the data back in from the temporary table.

    For example, suppose you have a table named "t1" with columns names "a", "b", and "c" and that you want to delete column "c" from this table. The following steps illustrate how this could be done:

    BEGIN TRANSACTION;
    CREATE TEMPORARY TABLE t1_backup(a,b);
    INSERT INTO t1_backup SELECT a,b FROM t1;
    DROP TABLE t1;
    CREATE TABLE t1(a,b);
    INSERT INTO t1 SELECT a,b FROM t1_backup;
    DROP TABLE t1_backup;
    COMMIT;
    

    How to delete or add column in SQLITE?

    Delete column from SQLite table

    EDIT

    this is the solution for your problem said in comment:

    here,

    public void onListItemClick(ListView parent, View view, int position, long id) {
            Intent intent = new Intent(this, EmployeeDetails.class);
            Cursor cursor = (Cursor) adapter.getItem(position);
            intent.putExtra("EMPLOYEE_ID", cursor.getInt(cursor.getColumnIndex("_id")));
            startActivity(intent);
    

    the problem is with your intent.!! you are passing this as the context, but here the this not referring to your Activity.. it is the onClick! your logcat may give you a NPE or illegal as exception, change to

    Intent intent = new Intent(EmployeeList.this , EmployeeDetails.class);