SearchView上的监听器 - Ui似乎只有在其他地方点击时才会更新

时间:2014-10-20 14:59:37

标签: android gridview searchview

我的SearchView仅在失去焦点时才更新我的UI

我有一个带onTextListener的searchView

    //Keep a global variable of this so you can set it within the next listener
    SearchView user_search = (SearchView) search.getActionView();

    user_search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextChange(String newText) {
            final Intent intent = new Intent("menu-filtered-refreshed");
            intent.putExtra("filterText",newText);
            runOnUiThread(new Runnable() {
                @Override
                public void run() {

                    // You can also include some extra data.
                    LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent);

                }
            });
            Log.d("Text has changed to :", newText );

            return true;
        }


        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }
    });

在我收到广播的片段中:

@Override
public void onActivityCreated(Bundle savedInstanceState){

    super.onActivityCreated(savedInstanceState);
....
    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mMessageReceiver,
            new IntentFilter("menu-filtered-refreshed"));


}


// Our handler for received Intents. This will be called whenever an Intent
// with an action named "menu-filtered-refreshed" is broadcasted.
public BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        // Get extra data included in the Intent    - could get data but not using it, directly using the fragment
        //  String message = intent.getStringExtra("message");
        /* retrieve restaurant list */

        filterText = intent.getStringExtra("filterText").toUpperCase();
        menuGridAdapter.filterText = filterText;
        Log.d("An Intent is ", filterText);
        menuGridAdapter.Test(filterText);
        // menuGridAdapter.notifyDataSetInvalidated(); doesn't work either
        menuGridAdapter.notifyDataSetChanged();
    }
};

我的Test()方法只计算filteredList。然后我想调用notifyDataSetChanged()来更新我的gridview。

当我失去焦点时,我的GridView视图只有在我点击操作栏之外的某个地方(基本上)时才会更新。我希望我的GridView视图能够实时更新。我在这里遗漏了什么或这是预期的行为吗?

0 个答案:

没有答案