-4

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;

        }

1 Answers1

0

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);
Community
  • 1
  • 1
Blue_Alien
  • 2,148
  • 2
  • 25
  • 29
  • 1
    Tnx bachu for answer. I am beginer, so found simpler solution. I created new project with new database:) When I start app it works, but when click on item appears unffortunatly stoped :/ – Bogdan Skoric Nov 20 '14 at 06:26
  • post the logcat, probably bcz of the contxt.. and modified my ans by guess.. please check it – Blue_Alien Nov 20 '14 at 06:38
  • I am grateful to you for your answers bachu. I posed logCat beyond. – Bogdan Skoric Nov 20 '14 at 14:30
  • App running, but when I click on item it says unffortunatly stoped. My adapter = new SimpleCursorAdapter is coated, and painted in yelow :/ My logCat and explanation of the problem is beyond (answer 2). – Bogdan Skoric Nov 20 '14 at 15:05