如何阻止toast & alertDialog失去对EditText过滤器的关注

时间:2021-11-15 19:32:56

UPDATE:

更新:

latest update - getChanges() method has been added.

已经添加了最新的update - getChanges()方法。

second update - I have added the whole of my ShoppingList.java class.

第二次更新——我已经添加了我所有的购物清单。java类。

first update - After 2 people liking the question but no answers, I have opened up a bounty for this question.

第一次更新——在两个人喜欢这个问题但没有答案之后,我为这个问题打开了一个赏金。

Question:

问题:

I have had similar issues to this where I am unable to to re-filter my ListView once I start a new intent and then return back to the original page. This was solved with the use of an overiding the onResume() method and recalling my filter code from another filter method.

我遇到过类似的问题,一旦我开始一个新的意图,然后返回到原始页面,我就无法重新过滤ListView。通过使用覆盖onResume()方法并从另一个filter方法中调用我的过滤器代码来解决这个问题。

The latest issue Im having is should a dialogBuilder or a toast message be used on my app page, then once again the filter text is blanked i.e any text entered into my filter EditText is ignored by my filter.

我遇到的最新问题是,是否应该在我的应用页面上使用对话框构建器或吐司消息,然后过滤文本再次被删除。任何输入到我的过滤器EditText的文本都会被我的过滤器忽略。

Here are some screenshots to highlight the issue:

以下是一些突出问题的截图:

Loaded ListView of the items:

已加载项目列表视图:

如何阻止toast & alertDialog失去对EditText过滤器的关注

A search term is entered into the filter EditText and filter correctly:

将搜索词输入到filter EditText中,并进行正确的过滤:

如何阻止toast & alertDialog失去对EditText过滤器的关注

The first item 'A' is edited to 'AB'. The toast message confirms the action:

第一个条目“A”被编辑为“AB”。祝酒词证实了这一行动:

如何阻止toast & alertDialog失去对EditText过滤器的关注

This is the issue, the dialogbuilder(which is how the item is edited) and toast message are complete, a new filter term is entered into the EditText and the filter no longer filters:

这就是问题所在,对话框构建器(这是编辑条目的方式)和吐司消息是完整的,一个新的过滤项被输入到EditText中,过滤器不再过滤:

如何阻止toast & alertDialog失去对EditText过滤器的关注

Here is my filter code:

下面是我的过滤代码:

package com.example.flybaseapp;



    public class ShoppingList extends ListActivity implements OnClickListener {

Button AddItem;
Button showShop;
ListView showItems;
SimpleCursorAdapter cursorAdapter;
Long itemId;
TextView totalPrice;
String itemDescription;
int itemAmount;
int itemPrice;
EditText itemNameEdit;
DBHandlerShop getCons;
Dialog e1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.shoppinglistlayout);

    AddItem = (Button) findViewById(R.id.btnAddItem);
    showShop = (Button) findViewById(R.id.btnSearchShops);

    showItems = (ListView) findViewById(android.R.id.list);

    totalPrice = (TextView) findViewById(R.id.totalListPrice);

    AddItem.setOnClickListener(this);
    showShop.setOnClickListener(this);

    setList();

    int setPrice = updateTotal();
    totalPrice.setText(Integer.toString(setPrice));

    itemNameEdit = (EditText) findViewById(R.id.inputItemName);

    showItems.setTextFilterEnabled(true);

    itemNameEdit.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before,
                int count) {

            cursorAdapter.getFilter().filter(s.toString());
            showItems.refreshDrawableState();

        }

    });

    getCons = new DBHandlerShop(this, null, null);
    getCons.open();
    cursorAdapter.setFilterQueryProvider(new FilterQueryProvider() {

        public Cursor runQuery(CharSequence constraint) {

            return getCons.getChanges((constraint.toString()));

        }

    });

    showItems.setAdapter(cursorAdapter);

}

@Override
public void onClick(View clickedAdd) {

    switch (clickedAdd.getId()) {

    case (R.id.btnAddItem):

        show();

        break;

    case (R.id.btnSearchShops):

        Intent checkGPS = new Intent("com.example.flybaseapp.CheckGPS");
        startActivity(checkGPS);

        break;

    }

}

@Override
protected void onListItemClick(ListView l, View v, int position, long idd) {
    super.onListItemClick(l, v, position, idd);

    itemId = idd;

    final CharSequence[] items = { "Edit Item", "Delete Item" };

    Builder alertDialogBuilder = new AlertDialog.Builder(ShoppingList.this);

    alertDialogBuilder.setTitle("Item Options:");

    alertDialogBuilder.setItems(items,
            new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int item) {

                    if (items[item].equals("Edit Item")) {

                        AlertDialog.Builder builder = new AlertDialog.Builder(
                                ShoppingList.this);

                        builder.setTitle("Edit Item");

                        DBHandlerShop setEdit = new DBHandlerShop(
                                ShoppingList.this, null, null);

                        setEdit.open();
                        String itemName = setEdit.getItem(itemId);
                        int itemAmount = setEdit.getItemQuan(itemId);
                        int itemPrice = setEdit.getItemCost(itemId);
                        setEdit.close();

                        LinearLayout layout = new LinearLayout(
                                ShoppingList.this);
                        layout.setOrientation(LinearLayout.VERTICAL);

                        final EditText titleBox = new EditText(
                                ShoppingList.this);
                        titleBox.setText(itemName);
                        titleBox.setHint("Item Name:");
                        layout.addView(titleBox);

                        final EditText quantityBox = new EditText(
                                ShoppingList.this);
                        quantityBox.setText(Integer.toString(itemAmount));
                        quantityBox.setHint("Item Quantity");
                        layout.addView(quantityBox);

                        final EditText priceBox = new EditText(
                                ShoppingList.this);
                        priceBox.setText(Integer.toString(itemPrice));
                        priceBox.setHint("Item Price.");
                        layout.addView(priceBox);

                        builder.setView(layout);

                        builder.setPositiveButton("Ok",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(
                                            DialogInterface dialog,
                                            int whichButton) {

                                        Editable valueItem = titleBox
                                                .getText();
                                        Editable valueAmount = quantityBox
                                                .getText();
                                        Editable valuePrice = priceBox
                                                .getText();

                                        String itemDescription = valueItem
                                                .toString();
                                        String s = valueAmount.toString();
                                        int itemAmount = Integer
                                                .parseInt(s);
                                        String a = valuePrice.toString();
                                        int itemPrice = Integer.parseInt(a);

                                        try {
                                            DBHandlerShop update = new DBHandlerShop(
                                                    ShoppingList.this,
                                                    null, null);

                                            int totalCombined = itemAmount
                                                    * itemPrice;

                                            update.open();
                                            update.updateItem(itemId,
                                                    itemDescription,
                                                    itemAmount, itemPrice);
                                            update.close();

                                            int setPrice = updateTotal();
                                            totalPrice.setText(Integer
                                                    .toString(setPrice));

                                        } catch (Exception e) {

                                            Toast.makeText(
                                                    getApplicationContext(),
                                                    "Items not updated.",
                                                    Toast.LENGTH_SHORT)
                                                    .show();

                                        } finally {

                                            Toast.makeText(
                                                    getApplicationContext(),
                                                    "Items updated.",
                                                    Toast.LENGTH_SHORT)
                                                    .show();

                                            setList();

                                        }

                                    }

                                });

                        builder.setNegativeButton("Cancel",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(
                                            DialogInterface dialog,
                                            int whichButton) {

                                    }
                                });

                        builder.show();

                    }

                    else if (items[item].equals("Delete Item")) {
                        try {

                            DBHandlerShop delete = new DBHandlerShop(
                                    ShoppingList.this, null, null);

                            delete.open();
                            delete.deleteItem(itemId);
                            delete.close();

                            DBHandlerShop findPrice = new DBHandlerShop(
                                    ShoppingList.this, null, null);

                            findPrice.open();
                            int returnedCost = findPrice
                                    .getItemCost(itemId);
                            findPrice.close();

                            int cost = updateTotal();

                            int newTotal = cost - returnedCost;
                            totalPrice.setText(Integer.toString(newTotal));
                        }

                        catch (Exception e) {

                            Toast.makeText(getApplicationContext(),
                                    "Item failed to be deleted.",
                                    Toast.LENGTH_SHORT).show();
                        }

                        finally {

                            Toast.makeText(getApplicationContext(),
                                    "Item deleted from the list.",
                                    Toast.LENGTH_SHORT).show();

                            setList();
                        }

                    }

                }

            });

    alertDialogBuilder.show();

}

@SuppressWarnings("deprecation")
private void setList() {

    DBHandlerShop DBShop = new DBHandlerShop(this, null, null);

    DBHandlerShop searchItems = new DBHandlerShop(this, null, null);

    searchItems.open();

    Cursor cursor = searchItems.getItems();

    startManagingCursor(cursor);

    searchItems.close();

    String[] from = new String[] { DBShop.KEY_ITEMSHOP, DBShop.KEY_ITEMNUM,
            DBShop.KEY_ITEMPRICE };
    int[] to = new int[] { R.id.txtSetItem, R.id.txtSetAmount,
            R.id.txtSetPrice };

    cursorAdapter = new SimpleCursorAdapter(this, R.layout.setshoppinglist,
            cursor, from, to);
    showItems.setAdapter(cursorAdapter);

}

private int updateTotal() {

    DBHandlerShop total = new DBHandlerShop(this, null, null);

    int totalPrice = 0;
    total.open();
    Cursor totalPrices = total.getTotals();
    total.close();

    if (totalPrices != null) {

        startManagingCursor(totalPrices);
        if (totalPrices.moveToFirst()) {

            do {
                int cost = totalPrices.getInt(3);
                int amount = totalPrices.getInt(2);

                int totalCost = cost * amount;
                totalPrice += totalCost;

            } while (totalPrices.moveToNext());

            return totalPrice;
        }

    }

    else {

        return totalPrice;

    }

    return 0;

}

private void show() {

    AlertDialog.Builder builder = new AlertDialog.Builder(ShoppingList.this);

    builder.setTitle("Enter Item Details:");

    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);

    final EditText titleBox = new EditText(this);

    titleBox.setHint("Item Name:");
    layout.addView(titleBox);

    final EditText quantityBox = new EditText(this);

    quantityBox.setHint("Item Quantity");
    layout.addView(quantityBox);

    final EditText priceBox = new EditText(this);

    priceBox.setHint("Item Price.");
    layout.addView(priceBox);

    builder.setView(layout);

    builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            try {

                Editable valueItem = titleBox.getText();
                Editable valueAmount = quantityBox.getText();
                Editable valuePrice = priceBox.getText();

                itemDescription = valueItem.toString();
                String s = valueAmount.toString();
                itemAmount = Integer.parseInt(s);
                String a = valuePrice.toString();
                itemPrice = Integer.parseInt(a);

                DBHandlerShop addItem = new DBHandlerShop(
                        ShoppingList.this, null, null);
                addItem.open();
                addItem.insertItems(itemDescription, itemAmount, itemPrice);
                addItem.close();

            } catch (Exception e) {

                Toast.makeText(getApplicationContext(),
                        "Item failed to be added", Toast.LENGTH_SHORT)
                        .show();

            } finally {

                Toast.makeText(getApplicationContext(),
                        "Item added to your list", Toast.LENGTH_SHORT)
                        .show();

                int cost = updateTotal();
                totalPrice.setText(Integer.toString(cost));

                setList();

            }

        }

    });

    builder.setNegativeButton("Cancel",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {

                }
            });

    builder.show();

}

@Override
protected void onResume() {
    super.onResume();

    setList();

    showItems.setTextFilterEnabled(true);

    itemNameEdit.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before,
                int count) {

            cursorAdapter.getFilter().filter(s.toString());
            showItems.refreshDrawableState();

        }

    });

    getCons = new DBHandlerShop(this, null, null);
    getCons.open();
    cursorAdapter.setFilterQueryProvider(new FilterQueryProvider() {

        public Cursor runQuery(CharSequence constraint) {

            return getCons.getChanges((constraint.toString()));

        }

    });

    showItems.setAdapter(cursorAdapter);
}

}

getChanges() from the Database Handler class:

来自数据库处理程序类的getChanges():

public Cursor getChanges(String constraintPassed) {

        String [] columns = new String[]{KEY_ROWSHOPID, KEY_ITEMSHOP, KEY_ITEMNUM, KEY_ITEMPRICE};
        Cursor c = null;
         if(constraintPassed.equals(""))
         {
             c = ourDatabase.query(DATABASE_TABLESHOP, columns, null, null, null, null, null);

         }

         else
         {
            c = ourDatabase.query(DATABASE_TABLESHOP, columns, KEY_ITEMSHOP + " LIKE'" + constraintPassed + "%'", null, null, null, KEY_ITEMSHOP + " ASC", null);
         }

        if( c != null)
            {
                c.moveToFirst();

            }
        return c;
    }

Do I need to implement a life-cycle method once the edit has been made? If so could someone push me in the right direction of which is needed as I have tried onResume() and onRestart() to no avail.

编辑完成后,是否需要实现生命周期方法?如果是这样的话,有人能把我推到需要的正确方向上吗?因为我尝试了onResume()和onRestart(),但没有成功。

6 个解决方案

#1


2  

Try calling notifyDataSetChanged() on your Adapter after you update the filter. This should notify the ListView that it needs to refresh its data also.

更新过滤器后,尝试在适配器上调用notifyDataSetChanged()。这应该通知ListView它也需要刷新它的数据。

#2


1  

As far as I can see, you are running getCons.open(); multiple times without closing it or so in between. I don't know whether that open() method ignores multiple calls or calling it multiple times causes an error, but you might want to try whether you can fix it by moving getCons.open(); directly below getCons = new DBHandlerShop(this, null, null);.

在我看来,您正在运行getcon .open();多次没有关闭它或在中间。我不知道open()方法是否会忽略多个调用或多次调用它会导致错误,但您可能想尝试通过移动getcon .open()来修复它;直接在getCons = new DBHandlerShop(this, null, null)下面;

#3


1  

A simple way around this issue I have found, is to simply recall the class by initiating a new intent object after the edit it complete. This still makes the overall operation of the process smooth and quick, and of course allows me to filter after an edit. So for the time being guys this is how Im going to go with it.

我发现解决这个问题的一个简单方法是,在编辑完成后,通过初始化一个新的intent对象来回忆类。这仍然使整个过程的操作变得平滑和快速,当然也允许我在编辑之后进行过滤。所以就目前而言,这就是我要做的。

#4


1  

I see what is happening in your case. Every time the user successfully edits an item, you are setting a new adapter to your list ! And in your case also, the TextWatcher added to your EditText in the onCreate method is using the very first adapter (in the onTextChanged method) also created in the onCreate method, the very first time the activity is created !

我了解你的情况。每次用户成功编辑一个项目时,您都在为您的列表设置一个新的适配器!在您的例子中,在onCreate方法中添加到EditText的TextWatcher也使用onCreate方法中创建的第一个适配器(在onTextChanged方法中),这是在创建活动的第一次!

There are several ways to solve this issue. One way would be to change the whole way you implemented your activity( I personally would not have done it this way ).

有几种方法可以解决这个问题。一种方法是改变你执行活动的整个方式(我个人不会这么做)。

Another way would be to simply alter the setList method, which is called the very first time in the onCreate method, and every time the user successfully edits an item. This is the solution I am going to explain in details since it is quick and easy and NOT time consuming for you :

另一种方法是简单地修改setList方法,这在onCreate方法中是第一次调用,每次用户成功编辑一个项目时都被调用。这是我将在细节上解释的解决方案,因为它既快捷又简单,而且不耗费时间。

  • If the list does not have a adapter, then create one.
  • 如果列表没有适配器,那么创建一个适配器。
  • If the list already has an adapter, then simply change the cursor of the adapter and refresh the list.
  • 如果列表已经有一个适配器,那么只需更改适配器的游标并刷新列表。

So your setList method should look like this :

你的setList方法应该是这样的:

@SuppressWarnings("deprecation")
private void setList() {

    DBHandlerShop DBShop = new DBHandlerShop(this, null, null);

    DBHandlerShop searchItems = new DBHandlerShop(this, null, null);

    searchItems.open();

    Cursor cursor = searchItems.getItems();

    startManagingCursor(cursor);

    searchItems.close();

    String[] from = new String [] { DBShop.KEY_ITEMSHOP , DBShop.KEY_ITEMNUM, DBShop.KEY_ITEMPRICE };
    int[] to = new int[] { R.id.txtSetItem, R.id.txtSetAmount, R.id.txtSetPrice };

    // Check the cursor adapter is previously created
    if ( cursorAdapter == null ) {
        // There is no previous cursors, create a new one
        cursorAdapter = new SimpleCursorAdapter(this, R.layout.setshoppinglist, cursor, from, to);
        showItems.setAdapter(cursorAdapter);
    }
    else {
        // There is a previous adapter
        // Stop managing its cursor
        stopManagingCursor ( cursorAdapter.getCursor() );
        // Assign the new cursor to the current adapter
        // The old cursor will be closed
        cursorAdapter.changeCursor ( cursor );
        // No need to refresh the list, it will be automatically refreshed after the adapter's cursor is changed
    }

}

In this manner, the adapter of the list is the same one that the TextWatcher is using to filter the list. It should work, give it a try and let me know what happens.

这样,列表的适配器就是TextWatcher用来过滤列表的适配器。它应该起作用,试着让我知道会发生什么。

#5


1  

I think you should use

我想你应该用

android:hapticFeedbackEnabled="true"
android:imeOptions="actionNext"
android:nextFocusUp="@id/editeText1" 
android:nextFocusLeft="@id/edittextText"
android:includeFontPadding="true"

#6


1  

You can try below changes..

你可以试试下面的改变。

After showing your toast items updated/deleted message call this

在显示您的吐司项目更新/删除消息后,请调用这个

cursorAdapter.notifyDataSetChanged();

In your setList() method add following..

在您的setList()方法中添加如下。

cursorAdapter.registerDataSetObserver(new DataSetObserver() {
@Override
public void onChanged() {
    super.onChanged();
    setList();
}});

and move below code to setList()

并将下面的代码移动到setList()

itemNameEdit.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                                      int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before,
                                  int count) {

            cursorAdapter.getFilter().filter(s.toString());
            showItems.refreshDrawableState();

        }

    });

    getCons = new DBHandlerShop(this, null, null);
    getCons.open();
    cursorAdapter.setFilterQueryProvider(new FilterQueryProvider() {

        public Cursor runQuery(CharSequence constraint) {

            return getCons.getChanges((constraint.toString()));

        }

    });

#1


2  

Try calling notifyDataSetChanged() on your Adapter after you update the filter. This should notify the ListView that it needs to refresh its data also.

更新过滤器后,尝试在适配器上调用notifyDataSetChanged()。这应该通知ListView它也需要刷新它的数据。

#2


1  

As far as I can see, you are running getCons.open(); multiple times without closing it or so in between. I don't know whether that open() method ignores multiple calls or calling it multiple times causes an error, but you might want to try whether you can fix it by moving getCons.open(); directly below getCons = new DBHandlerShop(this, null, null);.

在我看来,您正在运行getcon .open();多次没有关闭它或在中间。我不知道open()方法是否会忽略多个调用或多次调用它会导致错误,但您可能想尝试通过移动getcon .open()来修复它;直接在getCons = new DBHandlerShop(this, null, null)下面;

#3


1  

A simple way around this issue I have found, is to simply recall the class by initiating a new intent object after the edit it complete. This still makes the overall operation of the process smooth and quick, and of course allows me to filter after an edit. So for the time being guys this is how Im going to go with it.

我发现解决这个问题的一个简单方法是,在编辑完成后,通过初始化一个新的intent对象来回忆类。这仍然使整个过程的操作变得平滑和快速,当然也允许我在编辑之后进行过滤。所以就目前而言,这就是我要做的。

#4


1  

I see what is happening in your case. Every time the user successfully edits an item, you are setting a new adapter to your list ! And in your case also, the TextWatcher added to your EditText in the onCreate method is using the very first adapter (in the onTextChanged method) also created in the onCreate method, the very first time the activity is created !

我了解你的情况。每次用户成功编辑一个项目时,您都在为您的列表设置一个新的适配器!在您的例子中,在onCreate方法中添加到EditText的TextWatcher也使用onCreate方法中创建的第一个适配器(在onTextChanged方法中),这是在创建活动的第一次!

There are several ways to solve this issue. One way would be to change the whole way you implemented your activity( I personally would not have done it this way ).

有几种方法可以解决这个问题。一种方法是改变你执行活动的整个方式(我个人不会这么做)。

Another way would be to simply alter the setList method, which is called the very first time in the onCreate method, and every time the user successfully edits an item. This is the solution I am going to explain in details since it is quick and easy and NOT time consuming for you :

另一种方法是简单地修改setList方法,这在onCreate方法中是第一次调用,每次用户成功编辑一个项目时都被调用。这是我将在细节上解释的解决方案,因为它既快捷又简单,而且不耗费时间。

  • If the list does not have a adapter, then create one.
  • 如果列表没有适配器,那么创建一个适配器。
  • If the list already has an adapter, then simply change the cursor of the adapter and refresh the list.
  • 如果列表已经有一个适配器,那么只需更改适配器的游标并刷新列表。

So your setList method should look like this :

你的setList方法应该是这样的:

@SuppressWarnings("deprecation")
private void setList() {

    DBHandlerShop DBShop = new DBHandlerShop(this, null, null);

    DBHandlerShop searchItems = new DBHandlerShop(this, null, null);

    searchItems.open();

    Cursor cursor = searchItems.getItems();

    startManagingCursor(cursor);

    searchItems.close();

    String[] from = new String [] { DBShop.KEY_ITEMSHOP , DBShop.KEY_ITEMNUM, DBShop.KEY_ITEMPRICE };
    int[] to = new int[] { R.id.txtSetItem, R.id.txtSetAmount, R.id.txtSetPrice };

    // Check the cursor adapter is previously created
    if ( cursorAdapter == null ) {
        // There is no previous cursors, create a new one
        cursorAdapter = new SimpleCursorAdapter(this, R.layout.setshoppinglist, cursor, from, to);
        showItems.setAdapter(cursorAdapter);
    }
    else {
        // There is a previous adapter
        // Stop managing its cursor
        stopManagingCursor ( cursorAdapter.getCursor() );
        // Assign the new cursor to the current adapter
        // The old cursor will be closed
        cursorAdapter.changeCursor ( cursor );
        // No need to refresh the list, it will be automatically refreshed after the adapter's cursor is changed
    }

}

In this manner, the adapter of the list is the same one that the TextWatcher is using to filter the list. It should work, give it a try and let me know what happens.

这样,列表的适配器就是TextWatcher用来过滤列表的适配器。它应该起作用,试着让我知道会发生什么。

#5


1  

I think you should use

我想你应该用

android:hapticFeedbackEnabled="true"
android:imeOptions="actionNext"
android:nextFocusUp="@id/editeText1" 
android:nextFocusLeft="@id/edittextText"
android:includeFontPadding="true"

#6


1  

You can try below changes..

你可以试试下面的改变。

After showing your toast items updated/deleted message call this

在显示您的吐司项目更新/删除消息后,请调用这个

cursorAdapter.notifyDataSetChanged();

In your setList() method add following..

在您的setList()方法中添加如下。

cursorAdapter.registerDataSetObserver(new DataSetObserver() {
@Override
public void onChanged() {
    super.onChanged();
    setList();
}});

and move below code to setList()

并将下面的代码移动到setList()

itemNameEdit.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                                      int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before,
                                  int count) {

            cursorAdapter.getFilter().filter(s.toString());
            showItems.refreshDrawableState();

        }

    });

    getCons = new DBHandlerShop(this, null, null);
    getCons.open();
    cursorAdapter.setFilterQueryProvider(new FilterQueryProvider() {

        public Cursor runQuery(CharSequence constraint) {

            return getCons.getChanges((constraint.toString()));

        }

    });